File upload should assign cgi.FieldStorage to form.File field's value attribute

Bug #525260 reported by foxbunny
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
web.py
Confirmed
Undecided
Unassigned

Bug Description

File uploads seem to cause a little bit of confusion when it comes to retrieving the contents of the file, and the filename. I've attempted to address this issue as outlined here:

http://groups.google.com/group/webpy/browse_thread/thread/c6d0c7351a86c0b0/e29e98703ef8b176?lnk=gst&q=file+upload+branko+#e29e98703ef8b176

The attached patch makes this possible.

The patch modifies web.utils.storify to special-case the ``cgi.FileStorage`` and use its value without modification. It also modifies the form.File by overriding its set_value method. ``value`` propery of the file.File instance contains the entire ``cgi.FileStorage`` instance, file.File's ``filename`` attribute contains the filename, and ``file`` attribute contains the contents of the file.

The most important change that this patch introduces is that there is no longer any need to pass defaults to web.input() before performing form validation.

Revision history for this message
foxbunny (bg-branko) wrote :
Revision history for this message
Anand Chitipothu (anandology) wrote :

That will break backward-compatibility.

Changed in webpy:
milestone: none → 0.34
status: New → Won't Fix
Revision history for this message
foxbunny (bg-branko) wrote :

You're right. I'll try to redo the patch, though. Could you keep this open, perhaps with .35 milestone?

What I'm thinking is, that handle ``cgi.FileStorage`` differently, but also allow the previous behavior. I think it'd be really cool to not have to deal with File fields differently than with other fields.

Revision history for this message
Anand Chitipothu (anandology) wrote :

reopened and scheduled to 0.35.

Changed in webpy:
status: Won't Fix → Confirmed
milestone: 0.34 → 0.35
Revision history for this message
foxbunny (bg-branko) wrote :

This is not _completely_ backwards-compatible.

The old behavior was that, if the file field does not have {} as default value, it assigns file contents as value. If default is {}, FieldStorage instance is assigned as value. The former doesn't work anymore with this patch. Regardless of whether you set {} as default, or not, File field behaves exactly the same (which is kind of the point of this ticket).

Now a question: was the point of backwards-compatibility to keep the storify behavior where it gives you only the file contents if no default value is set in web.input? Personally, I think that is a bit pointless, but I'm sure it has its uses. Just not very convenient when you want to use it with web.form.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.