Multiple File uploads in Web.py

875 views
Skip to first unread message

Ben Hayden

unread,
Sep 12, 2011, 4:23:33 PM9/12/11
to we...@googlegroups.com
Hey guys,

I've got JavaScript for multiple file uploads, and all the file name attributes are labeled 'name'.

<div id="addAttachments_wrapper">
    <input type="file" name="upload">
    <input type="file" name="upload">
</div>

On the python side, I can't get a list of 'upload' field storage objects with both the filename & value.

With this:

query_data = web.input(upload=[])

I can get a list with string file upload values, but no filename.

With this:

query_data = web.input(upload={})

I only get the last upload FieldStorage with filename & value, so I lose the first upload.

Any ideas on how I can get both uploads & perserve both file names?

Devi

unread,
Sep 13, 2011, 3:59:34 AM9/13/11
to we...@googlegroups.com
You should possibly use different names like

<div id="addAttachments_wrapper">
<input type="file" name="upload1">
<input type="file" name="upload2">
</div>

and use query_data = web.input(upload={})

> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/webpy/-/oJDrri-l1YEJ.
> To post to this group, send email to we...@googlegroups.com.
> To unsubscribe from this group, send email to
> webpy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
>

--
~Devi

Anand Chitipothu

unread,
Sep 13, 2011, 4:12:00 AM9/13/11
to we...@googlegroups.com
2011/9/13 Ben Hayden <hayd...@gmail.com>:

Try using:

web.webapi.rawinput().get("upload")

The input function takes the return value of rawinput(..) and converts
to appropriate form. By calling the rawinput function directly you get
data without any conversion.

Anand

andrei

unread,
Sep 13, 2011, 6:22:57 AM9/13/11
to web.py
When using rawinput you might not get list of files when you're
uploading only one, then you have to ensure files to be list.

files = web.webapi.rawinput().get( "upload" )

if not isinstance(files, list):
files = [files]
for f in files:
# save every file





On Sep 13, 12:12 pm, Anand Chitipothu <anandol...@gmail.com> wrote:
> 2011/9/13 Ben Hayden <hayden...@gmail.com>:

Ben Hayden

unread,
Sep 13, 2011, 3:33:52 PM9/13/11
to we...@googlegroups.com

web.webapi.rawinput().get("upload")


Worked beautifully! Thanks Everyone!

Reply all
Reply to author
Forward
0 new messages