Hello,

file.stream has no attribute getvalue. But I found a workaround, which
I think is rather hackish:

file = request.files['uploaded_file']
file.seek(0, 2)           # seeks the end of the file
filesize = file.tell()    # tell at which byte we are
file.seek(0, 0)           # go back to the beginning of the file
img = PIL.Image.open(file)

Until I find out why the content_length is always zero, this will have
to make do.

Regards,
Tom

On Sep 23, 5:00 am, Robin B <[email protected]> wrote:
> Hi,
>
> The Content-Length header is not being sent, so Werkzeug punts and
> sets content_length=0.
>
> To get the size yourself, try len(file.stream.getvalue()).
>
> Robin
>
> On Sep 22, 8:57 am, tom <[email protected]> wrote:
>
>
>
> > Hello,
>
> > I'm trying to read the file size of an uploaded avatar before saving
> > it permanently.
>
> > file = request.files['uploaded_file']
> > if file:
> >     filename = file.filename          # this works
> >     filesize = file.content_length   # this is always zero
> >     img = PIL.Image.open(file)     # opening the file works
>
> > I think I tried everything but it still doesn't work. Sometimes
> > file.tell() gives me the file size after using it with PIL, but not
> > reliably. I had the same problem with uploaded audio files but there I
> > could work around it by using a metatag reader. Can anybody spot my
> > mistake? I'd be glad to add more info if needed.
>
> > Regards,
> > Tom
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to