2

I have a queue, when a user choose file(s), file(s) will be added to queue, this files may or may not choose at once

The problem is, on start uploading, each file open separate XHR connection and separate request, This is not OK for 2 main reasons,If a user choose 100 files, there would be one hundred concurrent connections!!, and 2, if a connection fail, whole upload will fail, I tried different things but none of them works, Is there any workaround for this ? maybe limiting concurrent upload ? I don't think that's an option since it only works in multi-part upload

Here is some information about what I'm doing

  1. I'm not using multi-part (using chunked upload).

  2. It's possible to user to choose files from different directory(I mean he/she can click on input every time he/she wants and append files to queue).

And here is the code I'm using:

// Upload queue array
var filesList = new Array();

$('#fileupload').fileupload({
  url: 'http://example.com/listener',
  maxChunkSize: 200000000,
  multipart: false,
  autoUpload: false,
  limitConcurrentUploads: 3,

  add: function(e, data) {
    // Just for rendering html table
    $.each(data.files, function(index, file) {
      $('#files table>tbody').append('<tr><td>' + file.name + '</td><td>' + humanFileSize(file.size) + '</td></tr>');
    });

    // Add to fileList array
    filesList.push(data);
  }
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');

// Start upload button
$(document).on('click', '#startup', function() {
  filesList.forEach(function(data) {
    data.submit();
  });
});

// Clear queue button
$(document).on('click', '#clearqueue', function() {
  $('#files table>tbody').html('');

  // Clear queue
  filesList.length = 0;

  // Replace file input element
  $("#fileupload").replaceWith($("#fileupload").val('').clone(true));
});
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Mojbala
  • 115
  • 1
  • 5

1 Answers1

0

There is the sequentialUploads option which defaults to false. Try setting it to true.

sequentialUploads (default: false)

Set this option to true to issue all file upload requests in a sequential order instead of simultaneous requests.

You can update your visual queue (if you got one) by using callbacks like:

fileuploadprocessdone

Callback for the successful end of an individual file processing queue.

$('#fileupload').bind('fileuploadprocessdone', function (e, data) {});

p1100i
  • 3,710
  • 2
  • 29
  • 45
  • thank, but I don't want the sequential upload, I want concurrent connections uploading, but limit active connections (like limitConcurrentUploads). And do you think that "File Processing Options" is the better solution to my queue handler? (instead of "fileList" array that used now) – Mojbala Apr 11 '16 at 18:39
  • i don't understand, for that usecase `limitConcurrentUploads` should work. is that not working for u? – p1100i Apr 11 '16 at 21:17
  • no not working :-( , I don't know why, but I guess the problem is the foreach submit of files for submit MY queue, and if I found solution for handle queue instead of fileList array, may be ```limitConcurrentUploads``` work fine... – Mojbala Apr 12 '16 at 04:39