views:

256

answers:

3

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
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
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
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
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
We can't set the value property of the normal file input. It is illegal.
jean27
+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
Thanks but our upload must be compatible with other browsers. Anyway, I'll check it out.
jean27

related questions