When there are multiple <input type="file" name="fname"> with the same name, web.input(fname={}) only returns the last one.

Bug #560278 reported by Hudson Lee
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
web.py
Fix Released
Undecided
Unassigned

Bug Description

In webpy .34 release.

When there are multiple <input type="file" name="fname"> with the same name, web.input(fname={}) only returns the last one.

This happens to be how: <input type="file" multiple=""> submits it's files.
(works in ff3.6 & recentish chrome/safari)

My fix for this is in utils.py storify() line 147: change
    else:
        value = value[-1]
TO:
    elif not isinstance(defaults.get(key), dict):
        value = value[-1]

Related Suggested Change:
I hate having todo: web.input(email=[], phone=[], userfile={}) to get lists when I have multiple form elements with the same name.

Why not be able to do something like this: web.input(_nolists=False) [I can't think of a good name] then in webapi.py input() line 278: add 1 line…
    defaults.setdefault('_nolists', True)

and in utils.py storify() add:
    _nolists = defaults.pop('_nolists')
… and ...
    elif _nolists and not isinstance(defaults.get(key), dict):
        value = value[-1]

That forces returning FieldStorage objects (instead of their .value) when you do web.input(_nolists=False). I think thats ok for a long list of files. People usually need the file name in any case.

A cleaner way to add this might be an input() wrapper something like web.inputs() which always returns lists for fields with the same name.

Let me know what you think about something like that.

-hudlee [<email address hidden>]

tags: added: file forms upload
tags: added: file-upload
removed: file upload
description: updated
summary: - When there are multiple <input type="file"> with the same name,
- web.input() only returns the last one.
+ When there are multiple <input type="file" name="fname"> with the same
+ name, web.input(fname={}) only returns the last one.
description: updated
description: updated
description: updated
description: updated
description: updated
Revision history for this message
Hudson Lee (public-nilmail) wrote :

This is how I would do it. Anyone like/hate this idea?

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

Moved this issue to github issues.

https://github.com/webpy/webpy/issues#issue/33

Changed in webpy:
status: New → Fix Released
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.