如何将base64编码的图像作为文件异步发布

How to post a base64 encoded image as a file asynchronously?

本文关键字:文件 异步 图像 base64 编码      更新时间:2023-09-26

我的API需要将图像作为文件发布到它。目前,我有一个base64格式的图像,它是由自定义图像创建器生成的。

我明白,如果我的形式有一个基本的inputfiletype,我可以使用new FormData(),然后沿着formData.append('file', myFile)的路线做一些事情。

我如何通过jQuery异步发布这个base64编码图像作为图像文件到我的API ?

在附加base64文件之前,将其转换为图像文件

var image = new Image();
image.src = 'data:image/png;base64,iVBORw0K...'; //put your base64 image here

现在将此图像附加为

formData.append('file', image);