11

I have base64 data URL in my angularJs controller, and I need an image file from that, so that I could send it to server as multi-part data through ajax?

I'm looking for something like file writer in angularjs. Can anyone help me please?

1 Answer 1

22

you can generate blob from base64 data.

var imageBase64 = "image base64 data";
var blob = new Blob([imageBase64], {type: 'image/png'});

From this blob, you can generate file object.

var file = new File([blob], 'imageFileName.png');

You can use this file object and post it to server using multipart data.

Sign up to request clarification or add additional context in comments.

4 Comments

Any time :) glad i helped :)
Althogh when I save the image, it says not a png file and won't let me view it. Can you tell why?
The blob file is going with content type as application/octet-stream, instead of image/png, to the server(python django), which is why I'm guessing it's not able to save it as image file. I'm not sure how to make a plunkr of this.
you can pass blob type in blob constructor. check my updated answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.