Writing byte stream as jpeg format to disk

Navkirat Singh navkirats at gmail.com
Thu Aug 26 15:47:18 EDT 2010


On 27-Aug-2010, at 1:10 AM, Robert Kern wrote:

> On 8/26/10 1:25 PM, Navkirat Singh wrote:
>> 
>> On 26-Aug-2010, at 11:01 PM, John Bokma wrote:
>> 
>>> Navkirat Singh<navkirats at gmail.com>  writes:
>>> 
>>>> 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.
>>> 
>>> Why?
>>> 
>>> --
>>> John Bokma                                                               j3b
>>> 
>>> Blog: http://johnbokma.com/    Facebook: http://www.facebook.com/j.j.j.bokma
>>>    Freelance Perl&  Python Development: http://castleamber.com/
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>> 
>> why? I am not quite sure what you have not understood.
> 
> Why decode the bytes to (presumably) unicode strings just to encode them back to bytes again? JPEG is not composed of unicode characters; you need to leave them as bytes.
> 
> -- 
> Robert Kern
> 
> "I have come to believe that the whole world is an enigma, a harmless enigma
> that is made terrible by our own mad attempt to interpret it as though it had
> an underlying truth."
>  -- Umberto Eco
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

The image bytes are a part of a HTTP header content ( not the message body ). To separate the header content from the image I have to first convert the bytes to string to perform parsing. The resultant string then needs to be converted back to the image. Hence, my problem.






More information about the Python-list mailing list