I'm trying to save a jpg image from a Flask app form. The following code works fine:
blob = request.files[canvas_key]
blob.stream.seek(0)
data = blob.stream.read()
string_io = cStringIO.StringIO(data)
string_io has type <cStringIO.StringI object at 0x10bf2bf10>
.
Yet when I try: Image.open(string_io)
, I get this error: IOError: cannot identify image file
.
Using stream.seek(0)
seems to solve this problem for other people, but in my case it hasn't.
string_io
prefix: 'RIFF\xa2_\x00\x00WEBPVP8 ', which makes sense, because I'm getting the image from 'image/webp, and "In 2010 Google introduced the WebP picture format, which uses RIFF as a container". This is the specific line of javascript that creates the image:
var dataURL = canvas.toDataURL('image/webp');` – Rose Perrone Jun 3 '14 at 21:04WebP
even existed when PIL was last updated. – Mark Ransom Jun 3 '14 at 21:09