Opened 14 years ago

Closed 14 years ago

#13582 closed (invalid)

multiple files uploaded with same name are not iterable

Reported by: anonymous Owned by: nobody
Component: File uploads/storage Version:
Severity: Keywords: multiple files POST
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am uploading a sound file with multiple images files associated using curl like this:

curl -X POST http://localhost:8000/analysis/test_post/ -F "file=@6.3gp" -v -F "image=@d1e98eee-f5af-41b1-9974-9d209816f2d3.jpg" -F "image=@gyoza.jpg"

and here is what I get if I put a breakpoint and play with an ipython shell:

In [1]: request.FILES
Out[1]: <MultiValueDict: {
	 u'image': [<InMemoryUploadedFile: d1e98eee-f5af-41b1-9974-9d209816f2d3.jpg (image/jpeg)>,
	            <InMemoryUploadedFile: gyoza.jpg (image/jpeg)>],
         u'file': [<InMemoryUploadedFile: 6.3gp (application/octet-stream)>]}>

In [2]: request.FILES.keys()
Out[2]: [u'image', u'file']

In [3]: request.FILES.values()
Out[3]:[<InMemoryUploadedFile: gyoza.jpg (image/jpeg)>,
	<InMemoryUploadedFile: 6.3gp (application/octet-stream)>]
		
In [4]: request.FILES['image']
Out[4]: <InMemoryUploadedFile: gyoza.jpg (image/jpeg)>

As you can see I only have one file when I query the dictionnary-like request.POST object hence I cannot iterate over it which is what I want to do.

Note that this ticket is similar to #12446 but I am using curl to do the upload as specified in their manual (at http://www.cs.sunysb.edu/documentation/curl/index.html):

To send two files in one post you can do it in two ways:
1. Send multiple files in a single "field" with a single field name:
curl -F "pictures=@dog.gif,cat.gif"
2. Send two fields with two field names:
curl -F "docpicture=@dog.gif" -F "catpicture=@cat.gif"

Both fail.

Change History (2)

comment:1 by anonymous, 14 years ago

FYI I am using Django 1.2

comment:2 by Karen Tracey, 14 years ago

Resolution: invalid
Status: newclosed

__getitem__ only returns the last value for multi-valued keys. See: http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict.__getitem

To get a list of all the values, you want to use request.FILES.getlist('image'). See: http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict.getlist

Note: See TracTickets for help on using tickets.
Back to Top