1

My API requires an image to be posted to it as a file. Currently, I have an image in base64 format that is generated by a custom image creator.

I understand that if my form had a basic input with the type of file I could use new FormData() and then do something along the lines of formData.append('file', myFile).

How can I post this base64 encoded image as an image file to my API via jQuery asynchronously?

Fizzix
  • 23,679
  • 38
  • 110
  • 176
  • 2
    possible duplicate of [Upload a base64 encoded image using FormData?](http://stackoverflow.com/questions/26667820/upload-a-base64-encoded-image-using-formdata) – Cayce K Jul 28 '15 at 12:35

1 Answers1

-1

Before appending your base64 file, convert it into an image file as

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

Now append this image as

formData.append('file', image);
sam100rav
  • 3,733
  • 4
  • 27
  • 43