Opened 15 years ago

Closed 11 years ago

#12446 closed New feature (wontfix)

multipart/mixed in multipart/form-data

Reported by: ssssssssssss Owned by:
Component: File uploads/storage Version: 1.1
Severity: Normal Keywords: multipart/mixed
Cc: Tom Christie Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Russell Keith-Magee)

The example is 'shamelessly' taken from RFC 1867

Trying to upload multiple files in one field name of form which seems will be supported by mozilla in the near future ( correct me if I'm wrong ). There is no error occurs, but I can't get files via request.FILES.

    """
    Content-type: multipart/form-data, boundary=AaB03x

    --AaB03x
    content-disposition: form-data; name="field1"

    Joe Blow
    --AaB03x
    content-disposition: form-data; name="pics"
    Content-type: multipart/mixed, boundary=BbC04y

    --BbC04y
    Content-disposition: attachment; filename="file1.txt"

    Content-Type: text/plain

    ... contents of file1.txt ...
    --BbC04y
    Content-disposition: attachment; filename="file2.gif"
    Content-type: image/gif
    Content-Transfer-Encoding: binary

      ...contents of file2.gif...
    --BbC04y--
    --AaB03x--
    """

Attachments (4)

chrome-10.0.txt (480 bytes ) - added by Tom Christie 14 years ago.
firefox-4.0.txt (545 bytes ) - added by Tom Christie 14 years ago.
safari-5.0.txt (480 bytes ) - added by Tom Christie 14 years ago.
opera-11.0.txt (662 bytes ) - added by Tom Christie 14 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 by Karen Tracey, 15 years ago

Ref to the new feature to allow multiple files to be selected for a single file input: http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/

comment:2 by wanliyou@…, 15 years ago

Even more, django can't handle multipart/mixed content directly

comment:3 by Russell Keith-Magee, 15 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted

comment:4 by Karen Tracey, 15 years ago

#13255 notes Chrome also supports multiple-file upload.

comment:5 by Jari Pennanen, 15 years ago

I'll put the links here I had in my duplicate, more details see blog post uploading multiple files using html5 and W3 File Upload State.

in reply to:  1 comment:6 by Florian Apolloner, 14 years ago

Owner: changed from nobody to Florian Apolloner
Status: newassigned

Replying to kmtracey:

Ref to the new feature to allow multiple files to be selected for a single file input: http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/

This works fine with trunk (request.FILES.getlist will give you all the files). Could it be that the reporter forgot to add enctype=multipart to his form?

comment:7 by Florian Apolloner, 14 years ago

Tested using:

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def test_view(request):
    for i in request.FILES.getlist('test'):
        print i.name
    return HttpResponse('<html><body><form action="." method="post" enctype="multipart/form-data"><input type="file" name="test" id="test" multiple=""><input type="submit"></form></body></html>')

comment:8 by Florian Apolloner, 14 years ago

Owner: Florian Apolloner removed
Status: assignednew

comment:9 by td123, 14 years ago

What is the status of this?
I would love to see this feature implemented.

comment:10 by Florian Apolloner, 14 years ago

Replying to td123:

What is the status of this?
I would love to see this feature implemented.

I am gonna close it as "worksforme", unless you can provide an example of what's not working…

comment:11 by Ramiro Morales, 14 years ago

I've tested apollo13's sample code as is and with a small tweak (adding a text field to the form to see if this forces the browser to send a multipart/mixed nested container inside the multipart/form-data) with Chrome 6:

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def test_view(request):
    if request.method == 'POST':
        #f = open('post_data.txt', 'w')
        #print >>f, request.META['CONTENT_TYPE']
        #print >>f, request.raw_post_data
        #f.close()
        for i in request.FILES.getlist('test'):
            print i.name
    return HttpResponse('''<html><body>
<form action="." method="post" enctype="multipart/form-data">
<input type="text" id="proj-search" name="q" size="10" accesskey="f" value="">
<input type="file" name="test" id="test" multiple="">
<input type="submit">
</form>
</body></html>''')

And things work correctly (all uploaded files are made available). But the browser isn't sending a multipart/mixed part (activate the commented out lines to get it dumped to a file).

Can't currently test with Firefox > 3.5 so I can't verify if Firefox behavior is different from Chrome.

Can any of the interested users (the OP, wanliyou, Ciantic td123) please clarify if multipart/mixed support is critical to the implementation of multi-file upload parsing?

comment:12 by Matt McClanahan, 14 years ago

Severity: Normal
Type: New feature

comment:13 by Tom Christie, 14 years ago

Cc: Tom Christie added

Okay, so according to the spec, yes "multipart/mixed" is defiantly required.

RFC 2388 - Returning Values from Forms: multipart/form-data

http://www.faqs.org/rfcs/rfc2388.html

'If multiple files are to be returned as
the result of a single form entry, they should be represented as a
"multipart/mixed" part embedded within the "multipart/form-data".'

W3C HTML 4.01 spec

http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2

'If multiple files are to be returned as the result of a single form entry, they should be returned as "multipart/mixed" embedded within the "multipart/form-data".'

W3C HTML 5 spec

http://www.w3.org/TR/html5/association-of-controls-and-forms.html#multipart-form-data

'Encode the (now mutated) form data set using the rules described by RFC 2388, Returning Values from Forms: multipart/form-data, and return the resulting byte stream.'

However, it appears that firefox, safari and chrome disregard this and simply return a flat list of files inside the "multipart/form-data" wrapper, and only opera conforms to the spec and returns a "multipart/mixed" wrapped inside the "multipart/form-data".

I've attached the files output from an upload of two simple text files in each case for future reference of anyone looking into this ticket.

So it looks like this Django currently handles multiple file uploads from firefox/safari/chrome just fine, but fails for opera (and fails according to the specs as they stand).

[attaching chrome-10.0.txt, firefox-4.0.txt, safari-5.0.txt, opera-11.0.txt]

by Tom Christie, 14 years ago

Attachment: chrome-10.0.txt added

by Tom Christie, 14 years ago

Attachment: firefox-4.0.txt added

by Tom Christie, 14 years ago

Attachment: safari-5.0.txt added

by Tom Christie, 14 years ago

Attachment: opera-11.0.txt added

comment:14 by anonymous, 13 years ago

Easy pickings: unset
UI/UX: unset

comment:15 by Tom Christie, 11 years ago

Resolution: wontfix
Status: newclosed

Given the previous note regarding the HTML 5 spec, and the lack of any further follow up on this ticket seeming to indicate a lack of this currently presenting an issue with existing browsers I'd suggest we close this ticket.

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