How to use Gridfs mongodb with PIL (Python Image Library)

I use mongodb and save the file in gridfs

now i want to edit images from gridfs ...

I am using this code

def thumbnail(file_obj): import StringIO from PIL import Image im = StringIO.StringIO() im.write(file_obj.raw_file) im_ful = Image.open(im) return im_ful.info 

but pil said "it is impossible to determine the image file"

this is also an image;) how to fix it?

+4
source share
1 answer

You need im.seek(0) before calling Image.open(im) . Otherwise, PIL tries to read from the end of the file, does not receive any data, and fails.

+6
source

Source: https://habr.com/ru/post/1337285/


All Articles