Is there any other way that I can just check the size of a file before upload? The requirement is if the file exceeded the limit, the form mustn't submit. If it's not, I have to do the ordinary upload using the form and I don't have to exactly upload the file to the server using Flash.
A:
Is there any other way that I can just check the size of a file before upload?
Not in JavaScript, the file size is not in the DOM.
Jonas Elfström
2010-02-03 07:25:50
A:
when instantiating SWFUpload, there are two parameters you need to pass: file_size_limit, and file_queue_error_handler:
new SWFUpload({
file_size_limit: "10 MB",
file_queue_error_handler: queueErrorHandler,
[...]
})
and then:
function queueErrorHandler(file, errorCode) {
if (errorCode == SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT) {
alert("File exceeds the 10MB limit!");
}
}
this checks if the file size is within limits before starting the upload
Victor Stanciu
2010-02-03 07:58:51
I just don't want to upload the file using Flash. I mean, I just want to check the size of the file using SWFUpload and then upload the file using the normal process. Does it seem possible?
jean27
2010-02-03 08:23:11
I also found out that I can't manipulate the value of input type file so I guess what I really want is impossible.
jean27
2010-02-03 08:26:04
yes, using SWFUpload just to check the file size would work if you could set the value property of the normal file input
Victor Stanciu
2010-02-04 10:36:22
We can't set the value property of the normal file input. It is illegal.
jean27
2010-02-15 09:02:53
+1
A:
hi,
with the W3C FileAPI (implemented at least by Firefox 3.6) you can.
See this link for details
http://hacks.mozilla.org/2009/12/w3c-fileapi-in-firefox-3-6/
Cheers
denisjacquemin
2010-02-04 15:18:53
Thanks but our upload must be compatible with other browsers. Anyway, I'll check it out.
jean27
2010-02-12 10:01:24