I am trying to update the formData for each chunk that is uploaded. However Blueimps jquery file upload plugin only allows you to set the formData once at the beginning.

The reason I need to be able to update the formData is so I can tell the server what current chunk it is on ie 3 out of 24 chunks.

Here is my code:

$('#fileupload').fileupload({
    maxChunkSize: 50024,
    url: '/webpanel/upload/blueimp/',
    dataType: 'json',
    success: function (data, textStatus, jqXHR) 
    {
        count = parseInt($('#chunk').val()) + 1;
        $('#chunk').val(count);         
        data.formData = {               
            chunk: $('#chunk').val()
        };
    },
    submit: function (e, data) 
    {   
        data.formData = { 
            fname: data.originalFiles[0].name,
            chunks: Math.ceil(data.originalFiles[0].size/maxChunkSize),
            chunk: $('#chunk').val()
        };
    }
});

Help appreciated

有帮助吗?

解决方案

If you haven't found a solution, try using the add function:

$('#fileupload').fileupload({
    add: function (e, data) {
          data.formData = { 
            fname: data.originalFiles[0].name,
            chunks: Math.ceil(data.originalFiles[0].size/maxChunkSize),
            chunk: $('#chunk').val()
            };
          data.submit();
    } 
});

You may need to watch the value of $('#chunk') and call the piece of code above when it changes.

I used something like this inside an AngularJS directive, and get inspired from: https://github.com/blueimp/jQuery-File-Upload/wiki/Submit-files-asynchronously#overriding-the-add-callback

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top