[Grok-dev] Problem with uploading image files and processing them
in the same request
Sebastian Ware
sebastian at urbantalk.se
Tue Jan 29 09:12:01 EST 2008
I am trying to upload image files and then creating a thumbnail in the
same request. I get a...
IOError: image file is truncated (57 bytes not processed)
Is this due to the fact that the file hasn't been written to disk yet,
and what can I do to avoid it?
This is the code that I have put in my grok.action('Save')...
obj.local_file_path = '/the/full/path/to/my/file'
...and I am saving an image posted through a HTTP form POST...
uploadedFile = self.request.form['upfile']
file = open(obj.local_file_path, 'wb')
file.write(uploadedFile.read())
file.close
...immediately opening it again, to create a thumbnail...
im = Image.open(obj.local_file_path)
size = 256,256
im.thumbnail(size)
im.save('%s.thumb' % obj.local_file_path, "JPEG")
Mvh Sebastian
More information about the Grok-dev
mailing list