简体   繁体   English

AngularJS:将base64图像上传到服务器

[英]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. 我已经生成了图像的base64数据,并将其输入到<img/>标记的src属性中,因此现在出现了图像。 But now next task is to upload the image file from the <img/> tag to the server. 但是现在的下一个任务是将图像文件从<img/>标记上传到服务器。 But since I've the base 64 of the image I don't know how to upload it to the server. 但是,由于我拥有映像的基数64,所以我不知道如何将其上传到服务器。

Please guide. 请指导。

You can send the Base 64 data to the server throw a normal AJAX POST. 您可以将Base 64数据发送到服务器,并发送普通的AJAX POST。

Even with jQuery: $.post('/save', {image: base_64_data}) 即使使用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. 然后,在服务器上, 如此答案所述 (PHP示例),您可以将映像保存在磁盘上或执行任何所需的操作。

As mentioned send it across as a base64 and convert it on the server. 如前所述,将其作为base64发送并在服务器上进行转换。 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. 它已经被编码为base64,无需将其转换为图像,即bmp,jpeg等,并且无需对立即解码发送的编码进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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