2

I am using jQuery-File-Upload to upload file asynchronously. But, I found that the add files button will keep adding files every time it select.

For example firstly I select File1.txt and click the summit. Then the second time , I add File2.txt and the selected file will be both File1.txt and File2.txt ! So when I click submit, the second time I will upload two files!

I would like to know how to get access to variable where the file-upload plugin store files to be submited, so I can emptify the variable in

    done: function(e, result){
        ....
    }

I knew there is a change callback, yet what the change callback received ( data.files) contain only the files selected this time, not the whole file list to be submitted.

I still have not solved this problem , I found my situation is the same as this POST and it's the same as this

Yet, nobody have found a satifatory answer. Though there are tricks to workaround.

Community
  • 1
  • 1
Allan Ruin
  • 5,229
  • 7
  • 37
  • 42

2 Answers2

1

I had a similar problem where previously uploaded files were included in the next upload. Just like you been struggling for hours. Until I tried the following solution.

On Add Function just add "change" event of the file input element like below:

$('#YourFileUploadElementId').change(function(e) {
     data.files.splice(0); // Clear All Existing Files
});

Full Example Below:

$('#YourFileUploadElementId').fileupload({
    // Some options
    add: function (e, data) {
        $('#YourFileUploadElementId').change(function(e) {
          data.files.splice(0); // Clear All Existing Files
        });
    },
    // Other Events
 });

Note: Just change the YourFileUploadElementId to your file upload element id.

Here is the complete example on jsfiddle.net

http://jsfiddle.net/dustapplication/cjodz2ma/5/

Joesel Duazo
  • 141
  • 1
  • 2
-1

I had a similar problem where previously uploaded files were included in the next upload. The solution I came up with is to keep track of all upload attempts by storing file names in an array and checking in the "send" callback (a callback for the start of each file upload request) if a file has been already uploaded (if this callback returns false, the file upload request is aborted).

For more details go here: https://stackoverflow.com/a/34092755/1222040

Community
  • 1
  • 1
Patryk K
  • 57
  • 3