1

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()

  • What happens if you drop the image into [Hashify](http://hashify.me/). Does the Base64 string in the resulting data URI match either of the strings you generated? – davidchambers Nov 04 '11 at 04:31

1 Answers1

1

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.

Community
  • 1
  • 1
Brian Nickel
  • 26,890
  • 5
  • 80
  • 110