How do you reset the file queue?

875 views
Skip to first unread message

mercia.d...@gmail.com

unread,
Jun 21, 2013, 10:15:29 AM6/21/13
to jquery-f...@googlegroups.com
This is a fairly simple question and I have seen it asked repeatedly yet no answer seems forthcoming.

I have add the file uploader to an MVC 4 project and it pretty much works. However there appears to a bug, and I say it is a bug because I can think of no plausible reason why this would the default behaviour.

For example I click browse to select a file "ABC.txt" and this gets added to the file queue, via the ADD callback.

I then click the upload button and this file is fired off to my server side script, I receive progress and the file completes.

This so far is correct behaviour however I then click browse again and select "DEF.txt" and add this to what should be a new file queue.

However when I upload I get both ABC.txt and DEF.txt uploaded to my server side code. This does not seem very logical and surely once the operation to complete the first file upload is "done" (regardless of how many files there were) the file queue should then be reset. I can see no reason why you would ever leave the file in the queue? It makes no sense yet there does not appear to be any way of resetting the queue from within jQuery.

Does anyone have a why of resetting the file queue?


Sylvain

unread,
Jun 27, 2013, 8:29:00 AM6/27/13
to jquery-f...@googlegroups.com
Hey there,

I found your post while I was searching the web with the same issue.

I found the solution to my problem, which I believe is the same as yours.

Have a look at this link:

I actually hide the input|type=file element, replacing it with another button. Then when the user choose the file, I simply show the file name with a "Remove" button. Clicking on remove just removes it, and allows the user to choose another one.

I then had the same problem: while starting the upload with a "start" button, two files came at the same time, and this is because my Start button is bound to a click event that sends the data via data.submit().

Adding a file binds the button once. Change it and adding another one binds the button another time, so when you click the button data.submit() is called twice.

Basically, when I click the "Remove" button, I also unbind the "Start" button with the click event, and thus the data.submit() form.

That saved half of my day and I kept my hair ;).

Good luck with that!

Sylvain
Reply all
Reply to author
Forward
0 new messages