Use JavaScript to test file uploads before the client sends the POST request

VERIFIED FIXED in 5.0.9

Status

--
enhancement
VERIFIED FIXED
10 years ago
3 years ago

People

(Reporter: mozilla.bugs, Assigned: cesar)

Tracking

unspecified
5.0.9

Details

(Whiteboard: [AMO508Testday])

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

10 years ago
If a user tries to upload a *.tif file or other unsupported format, the file is posted and then rejected.

Would is save time and server load to reject the file with a javascript regular expression before the upload begins?
(Reporter)

Updated

10 years ago
Whiteboard: [AMO508Testday]
OS: Windows XP → All
Summary: Use Javascript to test file uploads before the client sends the POST request → Use JavaScript to test file uploads before the client sends the POST request
Sounds like a good idea. Can we test the file size too? Probably.
Severity: normal → enhancement
Hardware: x86 → All
Assignee: nobody → cdolivei.bugzilla
Target Milestone: --- → 5.0.9
(Assignee)

Comment 2

10 years ago
Created attachment 395245 [details] [diff] [review]
v1

Checks for proper file name extension and checks file size (gecko only. If you know of a webkit/trident method, I'd love to hear it!).
Attachment #395245 - Flags: review?(clouserw)
Attachment #395245 - Flags: review?(clouserw) → review-
Comment on attachment 395245 [details] [diff] [review]
v1

Looks pretty good, though:

>+// Returns the largest file you can upload to the server, in bytes.
>+function getMaxFileSize() {
>+    $size = ini_get('upload_max_filesize');
>+    switch (substr($size, -1)) {
>+        case 'M' :
>+            return (int)$size * 1024;
>+        default :
>+            return $size; // assume bytes
>+    }
>+}
>+

wouldn't M be $size * 1024 * 1024?
Trident can apparently use ActiveX for this purpose, though I am not sure we want this: http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html

In fact, I'd vote for "no". We decided once upon a time to ask for Gecko+JavaScript in the Dev CP, and try to degrade gracefully where reasonable. Not checking file sizes pre-upload for IE users seems graceful enough to me.
(Assignee)

Comment 5

10 years ago
Created attachment 395500 [details] [diff] [review]
v2. now more right

Thanks Wenzel. You are right, it is 1024 * 1024.

I didn't know about the ActiveX method for IE, but for some reason I was surprised. But I agree; dealing with it on the server side is graceful enough for IE, or any other browsers for that matter.
Attachment #395245 - Attachment is obsolete: true
Attachment #395500 - Flags: review?
(Assignee)

Updated

10 years ago
Attachment #395500 - Flags: review? → review?(fwenzel)
Comment on attachment 395500 [details] [diff] [review]
v2. now more right

I tried it and it wfm, good job.
Attachment #395500 - Flags: review?(fwenzel) → review+
Thanks everyone.  r49610
Status: NEW → RESOLVED
Last Resolved: 10 years ago
Resolution: --- → FIXED
(Reporter)

Comment 8

10 years ago
Can we apply this to the profile user page where a user image is uploaded?  (Since that is what I meant to have this apply to and just didn't make it clear ;) ).  Thank you though for fixing it on the developer page, since I didn't catch it there.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
I'd like QA to check this for 5.0.9 so I'm re-resolving this bug.  Tanner, can you file another bug and put it in the 5.1 milestone for our next push?  (If you can't do the milestone I can after you file).  Thanks.
Status: REOPENED → RESOLVED
Last Resolved: 10 years ago10 years ago
Resolution: --- → FIXED
(Reporter)

Comment 10

10 years ago
Filed Bug 511932 and set milestone to 5.1.
Created attachment 396003 [details]
Post-fix screenshot
Verified FIXED; I tried .tif, .doc, .ppt, .gif, .jpeg, .png.
Status: RESOLVED → VERIFIED
Product: addons.mozilla.org → addons.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.