Hello, I'm working on a Django project that need to upload images and there's limit on the image file size(like 5M). I need to compress the image if it is larger than the upper limit. And my problem is *how can i return the compressed image data just like the format of file.read()?* Here's how I did: (1) get the image as a file object from the Django request.FILE (2) get file_data, which is to return, from file.read(). and compare the length of data. (3) Compress the image, using library Image, thumbnail function. *(4) Here comes my problem, How can return the compressed data with the format like file.read*
import Image def upload(request): """ return: file_data <- file.read() """ file = request.FILE['file'] #get the image as file object file_data = file.read() #read the file file_size = len(file_data) #get the file size of the image if cmp(file_size, MAX_SIZE): im = Image.open(file) im.thumbnail((128, 128), Image.ANTIALIAS) file_data = ???? #Help how can i return the same format like file.read() which didn't come into the 'if' part. return file_data -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f94d1c22-d5d0-41f2-b649-a4a9afc610cb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.