Writing byte stream as jpeg format to disk

MRAB python at mrabarnett.plus.com
Thu Aug 26 15:15:25 EDT 2010


On 26/08/2010 19:57, Navkirat Singh wrote:
> I am sorry, maybe I was not elaborate in what I was having trouble
> with. I am using a jpegcam library, which on my web page captures a
> webcam image and sends it to the server via the POST method. On the
> Server side (python 3), I receive this image as a part of header
> content in bytes (I know thats not how it should be done, but the
> author has some reason for it), so I first convert the headers to a
> string so I can separate them. From the separated headers I fish out
> the content of the image file (which is a string). This is where I
> get stuck, how am I supposed to convert it back to an image, so I can
> save as a jpeg on disk.
>
[snip]
What does that string look like? Try printing out repr(image[ : 100]).
If it looks like plain bytes, then write it to file. If it looks like a
series of hex digits, then decode to bytes before writing.



More information about the Python-list mailing list