Closed
Bug 165943
Opened 23 years ago
Closed 23 years ago
Patch: allow URL with "file://" scheme in HTML file upload form (input type="file")
Categories
(Core :: Layout: Form Controls, enhancement)
Tracking
()
RESOLVED
FIXED
People
(Reporter: t.bubeck, Assigned: john)
References
Details
(Whiteboard: [FIX])
Attachments
(1 file, 6 obsolete files)
|
1.99 KB,
patch
|
john
:
review+
darin.moz
:
superreview+
|
Details | Diff | Splinter Review |
Normally in form input fields of type "file" it is possible to use the file
browser to select a local file and upload this file. By using drag-and-drop from
other mozilla windows you normally get a full URL containing the scheme
"file://" which is written into the input field.
Without the patch, mozilla will try to open the file including the scheme and
will never find the file. Then it will not upload the file.
This patch changes mozilla so that it recognizes "file://" URLs and is able to
upload them. This makes it possible to use drag-and-drop to drop files onto file
input fields.
The patch is based upon mozilla-1.1. Could you please apply?
Thanks!
Till
--- content/html/content/src/nsHTMLInputElement.cpp-moz11 Sat Aug 31 21:34:22 2002
+++ content/html/content/src/nsHTMLInputElement.cpp Sat Aug 31 22:21:06 2002
@@ -103,7 +103,7 @@
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsIFileStreams.h"
-
+#include "nsNetUtil.h"
// XXX align=left, hspace, vspace, border? other nav4 attrs
@@ -2339,14 +2339,20 @@
//
if (type == NS_FORM_INPUT_FILE) {
- //
- // Open the file
- //
nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID,
&rv));
NS_ENSURE_SUCCESS(rv, rv);
- rv = file->InitWithPath(value);
+ if (Substring(value, 0, 6) == NS_LITERAL_STRING("file:/")) {
+ rv = NS_InitFileFromURLSpec(file, NS_ConvertUCS2toUTF8(value));
+ } else {
+ rv = file->InitWithPath(value);
+ }
+
+ //
+ // Open the file
+ //
+
if (NS_SUCCEEDED(rv)) {
//
| Assignee | ||
Comment 1•23 years ago
|
||
Good patch, thanks :) Three things:
(1) you only have to look for "file:" to determine if it's a file URL, according
to the way URLs work.
(2) I don't see a reason to move that comment--it works better up before the
init and file decl anyway.
(3) could you please upload the patch as an attachment? Standard procedure :)
I'll r= with those changes. It would be nice if we solve the general case (bug
121059), but I can live with just doing file: for now :)
CC'ing darin, who ought to sr= this.
Status: UNCONFIRMED → NEW
Ever confirmed: true
| Assignee | ||
Comment 2•23 years ago
|
||
*** Bug 124238 has been marked as a duplicate of this bug. ***
Comment 3•23 years ago
|
||
this patch will not compile against the trunk. NS_InitFileFromURLSpec has been
replaced by NS_GetFileFromURLSpec, which returns a nsIFile object.
| Reporter | ||
Comment 4•23 years ago
|
||
This patch changes mozilla so that it recognizes "file://" URLs and is able to
upload them. This makes it possible to use drag-and-drop to drop files onto
file input fields.
The patch is based upon the current mozilla CVS trunk and uses
NS_GetFileFromURLSpec as darin@netscape.com correctly requested.
Could you please apply?
I also thought about a more improved patch which uses nsStandardURL to allow an
arbitrary URL inside an input field. It will then take this URL, do an "open"
and feed the InputStream into the aFormSubmission->AddNameFilePair. However I'm
not sure what this means for a delay, if the URL takes a long time to download
or an error happens... Are you interested in this?
In any case it would be great if you apply the current patch, because I will
need some time to write the above mentioned (better) patch.
Comment 5•23 years ago
|
||
Comment on attachment 97472 [details] [diff] [review]
patch using NS_GetFileFromURLSpec
>+ rv = NS_GetFileFromURLSpec(NS_ConvertUCS2toUTF8(value),
if performance matters, you might want to ensure that the first 5 chars
equals "file:" before calling into GetFileFromURLSpec.
>+ if (NS_FAILED(rv)) {
>+ // this is no "file://", try as local file
>+ nsCOMPtr<nsILocalFile> localFile;
>+ rv = NS_NewNativeLocalFile(NS_ConvertUCS2toUTF8(value), PR_FALSE,
>+ getter_AddRefs(localFile));
this looks very suspicious... NS_NewNativeLocalFile expects text in
the native charset of the underlying file system. (e.g.., ISO-8859-1
if locale is en-US.) so, you need to call NS_NewLocalFile(value)
instead.
also iirc, file:// URLs are formatted using the native charset with
non-ASCII bytes URL escaped. in other words, if value is an URL,
then value had better be ASCII... but, if value contains any non-ASCII
unicode chars, then treating it as an URL is way wrong! you shouldn't
worry too much about this... NS_GetFileFromURLSpec should error out
(even if it doesn't do so today, which'd be a bug).
Attachment #97472 -
Flags: needs-work+
| Assignee | ||
Comment 6•23 years ago
|
||
I don't think this is extremely performance-critical--file inputs are rare and
for goodness sakes, we're opening and reading a file here :) But if you want to
check for file: it's OK by me.
The Native thing is a big deal. Some filesystems support storing filenames as
Unicode or UTF8. Though I wonder how we deal with that in file URLs? Probably
escape the non-ASCII characters with %..? So that we read in the URL as UTF8
after decoding? In that case we'd want to URL-encode the filename before
passing it in.
Passing the InputStream *directly* from a URL wouldn't work because we have to
know the stream's size immediately before we ever send it--we have to report it
as part of Content-Length header. But downloading into a string or file and
making a stream off of that would work (if you did a file you could use the
DELETE_ON_CLOSE feature, though there are nuances involved with re-POSTing that
would make this feature "fun" to implement).
Comment 7•23 years ago
|
||
i'm 90% sure that if value ever contained a file:// URL, that it would be
properly formatted already. anyways, it is not the responsibility of this patch
to ensure that. NS_ConvertUCS2toUTF8 is OK when calling NS_GetFileFromURLSpec
because the API currently says that that the input URL spec should be UTF8. so,
only change that is necessary is the NS_NewLocalFile(value) one.
| Reporter | ||
Comment 9•23 years ago
|
||
This is a slightly modified version of my prevois patch. It now uses
NS_NewLocalFile instead of NS_NewNativeLocalFile.
Attachment #97472 -
Attachment is obsolete: true
Comment 10•23 years ago
|
||
Comment on attachment 97617 [details] [diff] [review]
Patch with NS_GetFileFromURLSpec and NS_NewLocalFile
sr=darin
Attachment #97617 -
Flags: superreview+
| Assignee | ||
Comment 11•23 years ago
|
||
Comment on attachment 97617 [details] [diff] [review]
Patch with NS_GetFileFromURLSpec and NS_NewLocalFile
r=jkeiser
Do you have CVS access? Do you need someone to check this in for you?
Attachment #97617 -
Flags: review+
| Reporter | ||
Comment 12•23 years ago
|
||
Do you mean me (with CVS acess)? No, I don't have CVS access (also I am capable
of using CVS). Could someone else please check this in?
| Reporter | ||
Comment 13•23 years ago
|
||
Is there anything wrong with the patch? I didn't find it in mozilla 1.2 alpha...
Should I change anything to your needs?
Thanks!
| Assignee | ||
Updated•23 years ago
|
Status: NEW → ASSIGNED
Whiteboard: [FIX]
| Assignee | ||
Comment 14•23 years ago
|
||
Re-uploading the patch to test this bug
| Assignee | ||
Comment 15•23 years ago
|
||
Re-uploading with normal URL to test again (ignore)
Attachment #99135 -
Attachment is obsolete: true
| Assignee | ||
Comment 16•23 years ago
|
||
This is a slightly modified version of the patch incorporating darin's earlier
suggestion ... only because we are asserting now whenever we do a normal file
upload.
Attachment #97617 -
Attachment is obsolete: true
Attachment #99136 -
Attachment is obsolete: true
Comment 17•23 years ago
|
||
Comment on attachment 99141 [details] [diff] [review]
Patch v1.1
you probably want to use a case insensitive string compare since necko would
accept "FiLe:"
Attachment #99141 -
Flags: needs-work+
| Assignee | ||
Comment 19•23 years ago
|
||
Comment on attachment 99146 [details] [diff] [review]
Patch v1.1.1
r=jkeiser
Attachment #99146 -
Flags: review+
Comment 20•23 years ago
|
||
Comment on attachment 99146 [details] [diff] [review]
Patch v1.1.1
sr=darin
Attachment #99146 -
Flags: review+ → superreview+
| Assignee | ||
Updated•23 years ago
|
Attachment #99146 -
Flags: review+
| Assignee | ||
Comment 21•23 years ago
|
||
Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Comment 22•3 years ago
|
||
Comment 23•3 years ago
|
||
Comment on attachment 9260858 [details]
Bug 165943 - disable browser_nested_iframe.js on mac x64 r=#intermittent-reviewers
Revision D137036 was moved to bug 1659435. Setting attachment 9260858 [details] to obsolete.
Attachment #9260858 -
Attachment is obsolete: true
You need to log in
before you can comment on or make changes to this bug.
Description
•