问题
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