12

I use jQuery file upload blueimp and have read

$(function () {
    $('#fileupload').fileupload({
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        },
        add:function (e, data) {
            $("#uploadBtn").off('click').on('click',function () {
                data.submit();
            });
        }
    });
});

but this uploads a single file, I want to upload all files that have been selected.

3
  • whats your form code mainly the input section have you set this to <input type="file" name="files[]" multiple> have you also looked at their API details? Commented Dec 23, 2013 at 10:27
  • I have read API but not understand, because english bad... please Commented Dec 23, 2013 at 14:32
  • did you achievied how to solve your question? Commented Aug 5, 2014 at 3:36

3 Answers 3

10
var pendingList: [];

var sendAll: function () {
        pendingList.forEach(function (data) { data.submit(); });
        pendingList = [];
    };

$('#fileupload').fileupload({
    url: 'url_path',
    autoUpload: false,

    add: function (e, data) {
            pendingList.push(data);
        },


});

<button onclick="sendAll()">Start Upload All</button>
Sign up to request clarification or add additional context in comments.

1 Comment

That's the only way I can see how to do it. And it works.
8

your problem is that you unbind the click event on every file. you should do it on done:

done: function (e, data) {
            $("#uploadBtn").off('click')
            $.each(data.result, function (index, file) {
                $('<p/>').text(file.name).appendTo(document.body);
            });
        },
add: function (e, data) {
            $("#uploadBtn").on('click',function () {
                data.submit();
            });
        }

1 Comment

The "point" here is that calling data.submit() on a single file will upload that one file, by calling data.submit() on all the files from one button (#uploadBtn) it will add them all to the queue and upload them in turn.
1

For upload concurrently all file you have selected, you can add the option autoUpload: true, like this:

$('#fileupload').fileupload({
    url: 'url_path',
    autoUpload: true
})

Reference: https://github.com/blueimp/jQuery-File-Upload/wiki/Options

1 Comment

This answer is wrong, the autoUpload option triggers the upload when the file is selected. The question is about uploading more than one file at a button press.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.