[Image-SIG] Can't open image retrieved from S3 with PIL

Kevin J. Smith kevin at rootsmith.ca
Fri Jul 2 06:44:29 CEST 2010


Hi,

I know this may have to do with my use of S3 but I'm searching for any
little thread that I can hang onto to solve this problem.

If I retrieve an image from boto (S3) and then try and open it with PIL I
get an IOError: cannot identify image file.

Here is the code:

s3 = S3Connection('blah','blah')
bucket = s3.get_bucket('my_bucket')
key = bucket.get_key(key_name)
file = StringIO()
key.get_file(file)
Image.open(file)
# .. here I wish to crop the image before spitting it back to the calling
environment

I know that the file I retrieve with the "key.get_file(file)" statement is
in good shape because if I take out the PIL code and turn around and set the
Content-Type header to image/jpeg and fire the file object back at the
browser (this code is in a web app controller) the image appears just fine!

By briefly looking at the code in PIL it seems it is inspecting the first 16
bytes of the file and determining if it can recognize it but I don't
understand why it isn't recognizing it.

Any suggestions?

Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20100701/148ad3f6/attachment-0001.html>


More information about the Image-SIG mailing list