Question about file uploading

0 views
Skip to first unread message

riteshn

unread,
Apr 7, 2009, 9:59:59 PM4/7/09
to glashammer
Hi

I have a form with a file field. In request handler, I am doing the
following:

attachment = req.files[form.attachment.name]
data = attachment.read()
if len(data):
print(type(attachment))
print attachment.type
open(os.path.join(ATTACHMENTS_DIRECTORY,
attachment.filename), 'w').write(data)

>>>>

It throws up a traceback like: http://paste.pocoo.org/show/111558/

Though according to the doc at http://werkzeug.pocoo.org/documentation/wrappers,
it should have the property.

Similarly, attachment.data does not work but attachment.read() does.

What I might be missing?

-- Ritesh

Ali Afshar

unread,
Apr 8, 2009, 6:30:32 AM4/8/09
to glash...@googlegroups.com, pocoo...@googlegroups.com
riteshn wrote:
> Hi
>
> I have a form with a file field. In request handler, I am doing the
> following:
>
> attachment = req.files[form.attachment.name]
> data = attachment.read()
> if len(data):
> print(type(attachment))
> print attachment.type
> open(os.path.join(ATTACHMENTS_DIRECTORY,
> attachment.filename), 'w').write(data)
>
>
>
> It throws up a traceback like: http://paste.pocoo.org/show/111558/
>
> Though according to the doc at http://werkzeug.pocoo.org/documentation/wrappers,
> it should have the property.
>
Looking at the Werkzeug source at that revision [1], seems this is a
documentation bug in Werkzeug. The actual attribute is "content_type",
and "content_length" also exists. This seems to be the same in tip. I
have no idea if the docs have changed for the newer unreleased versions.


> Similarly, attachment.data does not work but attachment.read() does

"data" I am not sure about, are you getting the same exception?

Ali

[1]
http://dev.pocoo.org/projects/werkzeug/browser/werkzeug/utils.py?rev=663%3Aa93240c851ab#L421

Reply all
Reply to author
Forward
0 new messages