tags:

views:

73

answers:

2

Hello, I want to get an extension (or HTTP headers received) and base64-encoded (seems like JS doesn't have a built-in encoding function, so "binary" would be ok too) body of an image on a page. How can I do it?

This probably seems to be a weird action, but I really need to do it this way: I have a browser object and want to get such data from the last loaded page. The driver supports executing JS in the context of the current page so I think it is probably the best solution.

Update:

See, I already have a page with all the images on it and I don't want to request any of them again. I want to get the data string (like "GIF89a��÷–�Òíÿ…™ë�•懚í~’âÔîÿ}‘à‡�¤ÇãÿÓÕ䊜ë) of a certain image.

+1  A: 

Just use XmlHttpRequest to fetch the image? http://codingforums.com/showthread.php?t=141041

Do we mean "formatting the received data and display an hex dump"? You can probably consult a previous post related to this topic: http://stackoverflow.com/questions/327685/is-there-a-way-to-read-binary-data-into-javascript

jldupont
XmlHttpRequest will issue a new request, right?
roddik
If the image is cacheable (policy returned through the HTTP headers) then the browser might fetch it from its cache.
jldupont
+1  A: 

This question is a duplicate, and has been answered, albeit with a lot of discussion.

Another idea: If you can influence the source document, you could embed all images as inline images. The "src" attribute should then contain the whole base64 string, however I have never tried this out.

Pekka