ProgerXP / FileDrop

Self-contained cross-browser pure JavaScript class for Drag & Drop and AJAX (multi) file upload.
filedropjs.org
The Unlicense
264 stars 61 forks source link

Can't upload the same file twice in a row #12

Closed rafaelmaiolla closed 10 years ago

rafaelmaiolla commented 10 years ago

I thought this was a feature, but it turned out to be a bug. Steps to reproduce using the "File Explorer" (no drag and drop):

But you can upload the same file if you simple select another one between them:

This fix should be something like:

self.opt.input.file.value = ""
ProgerXP commented 10 years ago

I know about this and tries this but not all browsers support setting file's input value even to empty value. Notably Opera won't allow it.

Does it fix IE at least?

rafaelmaiolla commented 10 years ago

The input.files property is read-only, but you can set the value for the input to be "".

I will change the code in my "fork", so you can see that I'm talking about.

rafaelmaiolla commented 10 years ago

The change for that is the following: https://github.com/rafaelmaiolla/FileDrop/commit/7efc0fa8b0174abf961ff9ccfa31cd0f9c5e493c

I don't know if that is the proper place to add this code, but this worked on Chrome and will probably work on IE.

ProgerXP commented 10 years ago

Like I've said it (still) doesn't work on IE but at least it works on Chrome and Firefox (tested). Implemented in 528f2ca1891cb71e086fccd3f9c9f19699ef99c5. Thanks for another correction.

rafaelmaiolla commented 10 years ago

You can make it work on IE too. But you need to remove the old input and add a new one in its place. The following stackoverflow post explain how to do it using jQuery by cloning the old one, but you can do it on hand. http://stackoverflow.com/questions/1043957/clearing-input-type-file-using-jquery/1043969#1043969

ProgerXP commented 10 years ago

I'm not sure it's a good idea to swap the input every time - it will lose all event bindings which might have been added outside of FIleDrop as well.

I will think about this though.

rafaelmaiolla commented 10 years ago

I understand your concerns.

And I can implement the work-around for IE by myself...

If someone else need it, the code is the following (using jQuery - and of course this code is outside the library):

var $input = $(fileDrop.el).find(":file");
$input.replaceWith($input.clone());

fileDrop.opt.input = null;
fileDrop.hook(fileDrop.el);
ProgerXP commented 10 years ago

I will actually implement this in the next update with an option to disable input recreation (will be enabled by default). So stay tuned.

rafaelmaiolla commented 10 years ago

Great!

ProgerXP commented 10 years ago

Implemented in 276e066c1a3d0731c4b6fe70444f4ad15d613f54. Turned out to be not so trivial (who would have guessed IE clones "by reference" and triggers submit once per every clone even after removing the old input?).

opt.recreateInput is true by default so your fix should be redundant now.

rafaelmaiolla commented 10 years ago

thanks for that, I will download the newer version.