jQuery file uploader just sending one chunk

ぃ、小莉子 提交于 2020-01-06 14:21:54

问题


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:


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.



来源:https://stackoverflow.com/questions/17238894/jquery-file-uploader-just-sending-one-chunk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!