简体   繁体   中英

AngularJS : Upload base64 image to server

I've generated a base64 data of an image and fed it into the src attribute of the <img/> tag so now the image appears. But now next task is to upload the image file from the <img/> tag to the server. But since I've the base 64 of the image I don't know how to upload it to the server.

Please guide.

You can send the Base 64 data to the server throw a normal AJAX POST.

Even with jQuery: $.post('/save', {image: base_64_data})

Then in the server, as mentioned on this answer (PHP Example), you can save the image on disk or do whatever you want.

As mentioned send it across as a base64 and convert it on the server. It's already been coded to a base64, there is no need to convert it to an image, ie bmp, jpeg, etc., and take the performance hit of encoding the immediately decoding to send.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM