----- Original Message ----- From: <mac.gregor@gmx.de> To: "Tim Hicks" <tim@sitefusion.co.uk> Sent: Thursday, January 17, 2002 8:09 PM Subject: Re: ExtImage madness - upload fails from script (python)
Hi Tim,
I think the problem is this:
if len(request.form[photo].read()) == 0: ... else: ... manage_addExtImage(file=request.form[photo], ...)
the read() call in the if statement 'consumes' the data in the request (see it as a stream). So when ExtImage tries to read the image data from the request the stream has already been read and is empty. That's why the image size turns out to be 0 bytes.
You could either try to seek the stream to it's beginning (something like request.form[photo].seek(0)) but I'm not sure if that works. Otherwise you could read from the request into a StringIO object, then test the size (via seek(0, 2) and tell()) and then seek back to the start.
That was exactly the problem! In fact, your idea about using .seek(0) worked like a charm as well. So, my code now looks like... else: file = request.form[photo].seek(0) manage_addExtImage(file=file, ...) Thank you *so* much, you've saved my bacon :-))) tim