[Grok-dev] Problem with uploading image files and processing them in the same request

Sebastian Ware sebastian at urbantalk.se
Wed Jan 30 12:19:23 EST 2008


In case someone finds this question in the archive. Turns out it was a  
typo...

   file.close -> file.close()

Mvh Sebastian

29 jan 2008 kl. 15.12 skrev Sebastian Ware:

> 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
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list