Django

Code

Ticket #7651 (closed: fixed)

Opened 6 months ago

Last modified 6 months ago

Bug when uploading lists of files

Reported by: julien Assigned to: axiak
Milestone: 1.0 beta Component: HTTP handling
Version: SVN Keywords: upload, 2070-fix
Cc: axiak Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Hi,

I'm using the jquery plugin MultiFile? [1], which allows to dynamically create file fields in the form and then upload all the files when submitting the form. It used to work totally fine before #2070 was merged. In my view I could do this:

file_dicts = []
for file_input_name in request.FILES:
    file_dicts += request.FILES.getlist(file_input_name)

However, since #2070's merge, the last file selected with MultiFile? is duplicated.

uploaded_files = []
for file_input_name in request.FILES:
    uploaded_files += request.FILES.getlist(file_input_name)

uploaded_files returns:

list: [<TemporaryUploadedFile: test1.gif (image/gif)>, <TemporaryUploadedFile: test2.jpg (image/jpeg)>, <TemporaryUploadedFile: test2.jpg (image/jpeg)>]

The duplicate file to have an empty content. The problems happens both with TemporaryUploadedFile? and InMemoryUploadedFile?.

The MultiFile? plugin is used by a lot of people on different platforms and with different web frameworks, and it used to work fine before #2070's merge, so to me this looks like a bug.

My first assumption is that the problem is in django.http.multipartparser.py. The code must enter the loop one time too much in the end somehow.

[1] http://www.fyneworks.com/jquery/multiple-file-upload/

Attachments

7651-fixes.diff (5.5 kB) - added by axiak on 07/07/08 16:21:13.
Fixes with test for multiple files.

Change History

07/07/08 16:20:34 changed by axiak

  • status changed from new to assigned.
  • cc set to axiak.
  • needs_better_patch changed.
  • component changed from Core framework to HTTP handling.
  • needs_tests changed.
  • owner changed from nobody to axiak.
  • keywords changed from upload to upload, 2070-fix.
  • needs_docs changed.
  • has_patch set to 1.
  • stage changed from Unreviewed to Accepted.

Thanks for the bug report.

I'm attaching a patch with tests to fix this bug. Leaving it accepted until someone other than me verifies this patch.

07/07/08 16:21:13 changed by axiak

  • attachment 7651-fixes.diff added.

Fixes with test for multiple files.

07/07/08 17:06:33 changed by jacob

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7858]) Fixed #7651: uploading multiple files with the same name now work. Also, in order to test the problem the test client now handles uploading multiple files at once. Patch from Mike Axiak.


Add/Change #7651 (Bug when uploading lists of files)




Change Properties
Action