views:

6729

answers:

2

I have a PHP script that can encode a PNG image to a Base64 string (which is pretty easy since there's a PHP library that provides Base64 conversion)

I'd like to do the same thing using Javascript (in the XUL Javascript environment). I know how to open files, but I'm not sure how to do the encoding? I'm not used to working with binary data.

+6  A: 

Here

Also, search on "javascript base64 encoding" turns a lot of other options, the above was the first one.

Sunny
+11  A: 

If you're writing Mozilla-specific code, then you can use btoa() and atob() to convert to and from base64 encoding. Otherwise, use something like the function Sunny referenced.

Shog9
Note that this also works for webkit browsers, such as Safari.
Daniel Von Fange
but it does not work on iPhone3G with iOS 4.1. It does work on the simulator iPhone simulator when set to iPhone4 or iPhone.
Grant M