Last Comment Bug 649150 - Blobs do not have a filename if sent via FormData
: Blobs do not have a filename if sent via FormData
: dev-doc-complete, testcase
Product: Core
Classification: Components
Component: DOM: Core & HTML (show other bugs)
: unspecified
: All All
: -- normal (vote)
: mozilla7
Assigned To: Jonas Sicking (:sicking)
: 680423 (view as bug list)
Depends on:
  Show dependency treegraph
Reported: 2011-04-11 15:22 PDT by Jan Gerber
Modified: 2011-09-15 08:07 PDT (History)
10 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

Testcase for this bug (should be loaded from a non-file:/// url) (1.08 KB, text/html)
2011-04-16 13:31 PDT, arasdelsuelo
no flags Details
Patch to fix (1.79 KB, patch)
2011-06-28 18:06 PDT, Jonas Sicking (:sicking)
mounir: review+
Details | Diff | Review

Description Jan Gerber 2011-04-11 15:22:43 PDT
User-Agent:       Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0
Build Identifier: 

Sending a Blob with FormData, and empty filename is sent:

var blob = file.slice(0, 10);
var formData = new FormData();
formData.append('file', blob);

This gets send to the server:
 Content-Disposition: form-data; name="file"; filename=""

Sending an empty filename for a multipart file results in errors on some backends,
i.e. Django does not recognize this as a file. and treats it as a key/value POST instead.

Chrome sends this instead:
 Content-Disposition: form-data; name="file"; filename="Blobf98dc705ce2d4f82af47b470950a3c2c"

Firefox should also set a random value for filename since this is expected by many multipart parsers.

Reproducible: Always
Comment 1 arasdelsuelo 2011-04-16 13:31:10 PDT
Created attachment 526515 [details]
Testcase for this bug (should be loaded from a non-file:/// url)

This test case shows a file input, and when a file gets selected tries to upload the first Kb of that file to the current URL.

The file can't be opened directly, as POSTs to "file:" urls gets denied. Open from a local server instead.

Watching the sent data with a sniffer yelds the results Jan Gerber comments, with a filename="" on the POST. This causes PHP (and others) to reject the file, even if data was sent correctly.
Comment 2 Jonas Sicking (:sicking) 2011-04-20 14:27:39 PDT
Ugh. This needs to be specified in the spec for FormData :(
Comment 3 Jan Gerber 2011-04-20 14:35:52 PDT
Is sending an empty string allowed according to the rfcs describing multipart/form-data?
Comment 4 Christopher Blizzard (:blizzard) 2011-05-20 16:20:59 PDT
Jonas, what do you need to make progress?  Can you or Arun do the spec work required?
Comment 5 Jonas Sicking (:sicking) 2011-05-20 16:25:04 PDT
The spec side is blocked by Anne who is on a looooong trek. Suspect we should do this one ourselves.

Buried in sheriff stuff right now, but would love help remembering to fix this monday.
Comment 6 Mounir Lamouri (:mounir) 2011-06-06 08:15:02 PDT
(In reply to comment #5)
> Buried in sheriff stuff right now, but would love help remembering to fix
> this monday.

Which monday were you talking about? :)
Comment 7 Jonas Sicking (:sicking) 2011-06-06 08:24:00 PDT
Any, really :)
Comment 8 Christopher Blizzard (:blizzard) 2011-06-28 09:19:23 PDT
Hi.  Last update was 22 days ago.
Comment 9 Jonas Sicking (:sicking) 2011-06-28 18:06:07 PDT
Created attachment 542696 [details] [diff] [review]
Patch to fix
Comment 10 Mounir Lamouri (:mounir) 2011-06-29 06:02:21 PDT
Comment on attachment 542696 [details] [diff] [review]
Patch to fix

Review of attachment 542696 [details] [diff] [review]:
Comment 11 Jonas Sicking (:sicking) 2011-06-29 11:06:25 PDT
Checked in. Thanks for the quick review!
Comment 12 Tomas 2011-06-30 08:36:06 PDT
So fixed?
Comment 13 Jonas Sicking (:sicking) 2011-06-30 09:24:34 PDT
Comment 14 Christopher Blizzard (:blizzard) 2011-08-09 09:15:49 PDT
This was fixed in Firefox 7.
Comment 16 Kyle Huey [:khuey] ( 2011-08-20 05:14:04 PDT
*** Bug 680423 has been marked as a duplicate of this bug. ***
Comment 17 Ioana (away) 2011-09-15 08:07:36 PDT
As visible here:
the test referenced in this bug (content/base/test/fileutils.js) has passed.

Note You need to log in before you can comment on or make changes to this bug.