From MozillaZine Knowledge Base

I want to send an HTTP Request with some custom headers to a proxy server and save the response (a Jpeg file) to the local disk. I tried using XMLHttpRequest() for this, but that only seems to work for text files. (I am basically accessing XMLHttpRequest.response and writing that to a file using (file-output-stream)'s outputstream.write() )

I'd be very grateful if someone can provide an example for JPEG.