使用FormData上传base64编码的图像? [英] Upload a base64 encoded image using FormData?

查看:122
本文介绍了使用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编码的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆