Image broken after download from server

I have a very simple python script to download a jpg image to client, but it always return a broken image.
Really don’t know what’s missing. Can anyone help?

Here is the code:


import sys

filename = r"path\\image.jpg"
sys.stdout.write( "Content-Disposition: attachment; filename=image.jpg\\r\
"
	+ "Content-Type: image/jpeg\\r\
\\r\
"
	+ file(filename,"rb").read())

Here are the images on the server and downloaded:

Hi,
Your carriage returns look Windowsy to me; are you using Windows? If so, this might explain what’s going on:
http://code.activestate.com/recipes/65443-sending-binary-data-to-stdout-under-windows/

so even though you’re reading a binary file using “rb”, you’re writing a text file when using stdout, even with the attempt at setting MIME type.