Code

Opened 5 years ago

Closed 7 months 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: tomchristie 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 russellm)

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 tomchristie 3 years ago.
firefox-4.0.txt (545 bytes) - added by tomchristie 3 years ago.
safari-5.0.txt (480 bytes) - added by tomchristie 3 years ago.
opera-11.0.txt (662 bytes) - added by tomchristie 3 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 follow-up: Changed 5 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 5 years ago by wanliyou@…

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

comment:3 Changed 4 years ago by russellm

  • Description modified (diff)
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 4 years ago by kmtracey

#13255 notes Chrome also supports multiple-file upload.

comment:5 Changed 4 years ago by Ciantic

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.

comment:6 in reply to: ↑ 1 Changed 4 years ago by apollo13

  • Owner changed from nobody to apollo13
  • Status changed from new to assigned

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 Changed 4 years ago by apollo13

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 Changed 4 years ago by apollo13

  • Owner apollo13 deleted
  • Status changed from assigned to new

comment:9 Changed 4 years ago by td123

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

comment:10 Changed 4 years ago by apollo13

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 Changed 4 years ago by ramiro

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 Changed 3 years ago by mattmcc

  • Severity set to Normal
  • Type set to New feature

comment:13 Changed 3 years ago by tomchristie

  • Cc tomchristie 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]

Changed 3 years ago by tomchristie

Changed 3 years ago by tomchristie

Changed 3 years ago by tomchristie

Changed 3 years ago by tomchristie

comment:14 Changed 3 years ago by anonymous

  • Easy pickings unset
  • UI/UX unset

comment:15 Changed 7 months ago by tomchristie

  • Resolution set to wontfix
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.