使用FormData上传base64编码的图像?

编程入门 行业动态 更新时间:2024-10-22 23:01:35
本文介绍了使用FormData上传base64编码的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个jpeg作为base64编码的字符串。

I have a jpeg as a base64 encoded string.

var image = "/9j/4AAQSkZJRgABAQEAS..."

我想使用FormData将此jpeg上传到服务器。

I would like to upload this jpeg to the server using FormData.

var data = new FormData();

将图像附加到数据的正确方法是什么?

What is the proper way to append the image to data?

推荐答案

您的图像数据只不过是一个字符串,所以将它附加到您的FormData对象,如下所示:

Your image data is nothing more than a string, so append it to your FormData object like this:

data.append("image_data", image);

然后在服务器端,您可以将其直接存储在数据库中或将其转换为图像和存储它在文件系统上。你可能会发现这篇文章乐于助人。

Then on your server side you can store that directly in a database or convert it to an image and store it on the file system. You might find this post helpful.

更多推荐

使用FormData上传base64编码的图像?

本文发布于:2023-10-04 09:24:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467146.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   上传   FormData

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!