jQuery file uploader just sending one chunk

2019-09-15 19:02发布

I'm using the jQuery file uploader in my Django application.

I've got the problem that Django just receives one chunk of my big file. At first I thought that it might be an issue with my UploadFileHandler but when I log the chunksend event from the uploader it is just fired once (instead of 9 times in my case).

Any ideas why the uploader is just sending one chunk?

Here's my code:

$('#fileupload').fileupload({
            dataType: 'json',
            maxChunkSize: 10000000,
            add: function (e, data) {

                console.log(data);

                var uploadRow = $('#upload-item-master')
                                    .clone()
                                    .removeAttr('id')
                                    .appendTo("#upload-container")
                                    .hide()
                                    .fadeIn(1000);
                uploadRow.find('.name').text(data.files[0].name);                   

                var jqXHR = data.submit()
                        .always(function (result, textStatus, jqXHR) {
                             if(result.status == 201) {
                                uploadRow.find('.progress .bar').css('width','100%');
                                uploadRow.find('.progress').removeClass('active');
                             } else {
                                uploadRow.find('.progress .bar').css('width','100%');
                                uploadRow.find('.progress').removeClass('progress-success');
                                uploadRow.find('.progress').removeClass('progress-success');
                                uploadRow.find('.progress').addClass('progress-danger');
                             }
                        })
            },
            chunksend: function(e, data) {
                console.log("Chunk sent");
            },
            progress: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);

            }
        });

1条回答
该账号已被封号
2楼-- · 2019-09-15 19:44

The solution is that the plugin needs a JSON ok, everything else will be interpreted als something bad and the next chunk is not sent.

With this code

return HttpResponse(json.dumps({ 'status': 201 }), content_type="application/json")

the plugin sends chunk by chunk to the server. Unfortunately the server - beside correct headers - interprets them as seperate files and creates one new file per chunk... I've created a new question fo the new problem here.

查看更多
登录 后发表回答