Writing byte stream as jpeg format to disk

Dave Angel davea at ieee.org
Thu Aug 26 16:02:36 EDT 2010


Navkirat Singh wrote:
> Hey guys,
>
> I am programming a webserver, I receive a jpeg file with the POST method.The file (.jpeg) is encoded in bytes, I parse the bytes by decoding them to a string. I wanted to know how i could write the file (now a string) as a jpeg image on disk. When I try to encode the same string to a bytes and write them in binary format to disk, the file is not recognized as jpeg. I would be grateful if someone could help me with this.
>
>
> Regards,
> Nav 
>   
If by "decoding them to a string" you mean converting to Unicode, then 
you've already trashed the data.  That's only valid if the bytes had 
been encoded from valid Unicode characters, and then only if you use the 
corresponding decoding technique.

If you mean some other decoding, then the question is meaningless 
without telling us just what the decoding is, preferably with some code.

It also might be useful to know what version of Python you're using, 
when you post the code.

DaveA




More information about the Python-list mailing list