[Zope] how to block until an image is done uploading?

Roman Milner roman@speeder.com
23 Oct 1999 16:14:47 -0500


Hello.  I've got some code (I've included the code below) that lets
the user upload an image.  It then store the image twice - one in its
normal form and the other as a thumbnail (generated via PIL).

The problem is, when the image is large I sometimes get errors.  The
problem, I think, is that when I retrieve the data from the image in
order to thumbnailize it all of the data is not available yet and PIL
throws an IOError saying the image is truncated. Small images work
fine.

I did a print of len(image_data) and it is smaller than it should be.
However, eventually all of the data must become available because the
non thumbnail image show up just fine.

So, can anyone say if I have diagnosed the problem right and if so how
can I force things to wait until the upload is finished?  I've tried
just using a sleep, but that didn't work.  No matter how long the
sleep, I still get the error.  

Thanks,
^Roman


    def make_pictures(self, pic_folder, id, file):
        pic_folder.manage_addImage(id + '_thumbnail', file, id + '_thumbnail')
        pic_folder.manage_addImage(id, file, id)
        self._thumbnailize(getattr(pic_folder, id + '_thumbnail'))

    def _thumbnailize(self, imgOBJ):
        #try:
        out = StringIO.StringIO()
        inn = StringIO.StringIO(imgOBJ.data)
        # for some reason imgOBJ.data does not contain all of the
        # image data yet
        print len(imgOBJ.data)
        im = PIL.Image.open(inn)
        im.thumbnail((128,128))
        im.save(out, im.format)
        imgOBJ.update_data(out.getvalue())
        #except IOError:
        imgOBJ.update_data('')
        #return 1