Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert base64 data url to image file in angularjs

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?

like image 302
Aarohi Kulkarni Avatar asked Aug 07 '15 13:08

Aarohi Kulkarni


1 Answers

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.

like image 125
dhavalcengg Avatar answered Oct 14 '22 14:10

dhavalcengg