简体   繁体   中英

Convert image to base64

I'm trying to convert an image into base64 using javascript, however if I request the URL with jquery, and encode with javascript, the results are different than what I receive from here (http://www.scalora.org/projects/uriencoder/) when saving and uploading the image..

Is there any reason for this?

I'm just using $.get and base64 encoding function data()

Another SO Question covers this exact topic and has a solution that works for IE and Firefox. The short answer is that XHR really isn't designed for binary data and the data gets corrupted or truncated when converted to a string for XHR.responseText .

It would be best to Base 64 encode on the server side.

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