Why downloading a Blueimp jQuery file adds everything before. selected files, even if [replaceFileInput: false] and [maxNumberOfFiles: 1] are set to init?

I have only a normal form with some input fields and one file input field. I am using the Blueplay Jquery download plugin to upload a file. It seems to work if you select a file and after that click the "Download" button. But if you re-select the files to download, this saves the entire history of the selection, and after sending it sends all the XHR to the server.

I want to download only one currently selected file, not all previously selected files (in the file open dialog box).

Here is my js module for handling loading:

$(function () { $('#upload_form').fileupload({ dataType: 'json', autoUpload: false, fileInput: '#filechose_button', replaceFileInput: false, maxNumberOfFiles: 1, multipart: true, add: function (e, data) { $('#upload_button').click(function () { $('#upload_button').attr('disabled', true); ... data.submit(); ... }); }, done: function (e, data) { ... // successfully uploaded }, progressall: function (e, data) { ... // update a progress bar } }); }); 

The solutions I found here ( How to upload a file only once with the plugin to download the blueimp file? ) Seems to be not the best way (I see it as dirty), because simply disabling the click event still does not solve the problem of collecting all earlier selected files (type of memory leaks)

The maxNumberOfFiles: 1 option does not work for me.

+6
source share
1 answer

I had the same problem, my solution was to cancel the click event on my button and bind it when the add event is fired. Try it.

...

 add: function (e, data) { $('#upload_button').unbind('click'); data.context = $('#upload_button').bind('click', function () { ... data.submit(); } } 
+6
source

Source: https://habr.com/ru/post/944157/


All Articles