Blueimp file uploads one request - files are not sent

I have a form that allows you to upload files to various fields that are dynamically added to the form. I am using the Blueimp jQuery file upload plugin. I am trying to send multiple files on a single request. I do not want to send multiple requests. When I submit the form, the files that will be uploaded will not be included in the request. I support them in the filesList array in the add method and don't forget to override existing values. Then I use the send parameter to send the files. Although, they are not included in the ajax post. What am I missing? I have seen other users try to do this. However, I did not find a convincing working example. Below is my code:

  var fileList = [],
    exists = false;

$form.fileupload({
    autoUpload: false,
    singleFileUpload: false,
    url: '/handler.php',
    add: function(e, data) {
        exists = false;
        for(var i = 0, len = filesList.length; i < len; i++) {
            if(filesList[i].paramName === data.paramName) {
                // file already exists for this param, replace it
                exists = true;
                filesList[i] = data;
                break;
            }
        }

        // no file exists for this param, add it to array
        if(!exists) {
            filesList.push(data);
        }

        $form.off('submit').one('submit', function(e) {
            $form.fileupload('send', {
                files: filesList
            });

            return false;
        });
    }
})
+4
2

, , singleFileUpload s 's'.

:

singleFileUploads

XHR. false, .

. , multipart true ( ).

: boolean : true

+5

, data.submit().

:

, .

data.submit() Promise , jQuery .

-1

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


All Articles