views:

2659

answers:

3

I was trying to load an image client side and base64 encode the bytes returned by the server in order to pass it off to perform some processing. IE has a RequestBody property of the XMLHttpRequest object, but I can't seem to use it, and RequestText is truncated. In Firefox, RequestText is there, but seems corrupted.

+3  A: 

After a few days' effort I was able to make this work, although information on the Internet for doing such binary manipulation is fairly scarce. I think it may be useful for others, especially when dealing with Data URIs, so I've detailed my work here: http://emilsblog.lerch.org/2009/07/javascript-hacks-using-xhr-to-load.html

Emil Lerch
A: 

You could have the server return base64 text, rather than doing that encoding client side.

For example, (in ASP.NET) a request to /ImageAsBase64.ashx?file=/images/myimage.png could be coded to read the file, base64encode it, and stream it as a response.

It's really going to be pretty much the same thing in PHP or whatever.

Clyde
Unfortunately, in this scenario that wouldn't work - I needed data from some COTS software, and it did not have a base64 option.
Emil Lerch
A: 

If you're using COTS, you could always set up an intermediate gateway wherein the request is made and transformed (base64 encoded in this case) into something more palatable before being returned to the client.

Justin Johnson
I actually tried this; however, the images were specific to the user's session and I was unable to fake out the software to think the server was part of the same user session.
Emil Lerch