Upload a base64 encoded image using FormData?

I have a jpeg as a base64 encoded string.

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

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?


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.


I found this post (Convert Data URI to File then append to FormData) to be quite helpful. If your file is already represented as a base64 encoded string, you would first need to create a blob representation from that and then you can use FormData append.

链接地址: http://www.djcxy.com/p/5346.html

上一篇: FormData()不适用于Firefox和Internet Explorer; 只有Chrome可以

下一篇: 使用FormData上传base64编码的图像?