【问题标题】:jQuery file uploader just sending one chunkjQuery 文件上传器只发送一个块
【发布时间】:2013-06-18 19:12:47
【问题描述】:

我在我的 Django 应用程序中使用 jQuery 文件上传器。

我的问题是 Django 只收到了我的大文件的一大块。起初我认为这可能是我的UploadFileHandler 的问题,但是当我从上传者记录chunksend 事件时,它只会触发一次(而不是在我的情况下为 9 次)。

任何想法为什么上传者只发送一个块?

这是我的代码:

$('#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);

            }
        });

【问题讨论】:

  • @sunrize920 将标签改为javascript
  • 如果你向 django 视图发送 FormData() 会发生什么?
  • 对不起,我不明白你的问题。但是它会影响jquery插件的行为吗?

标签: javascript jquery django file-upload jquery-file-upload


【解决方案1】:

解决方案是插件需要JSON ok,其他所有内容都将被解释为错误的,并且不会发送下一个块。

使用此代码

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

插件逐块发送到服务器。不幸的是,服务器 - 除了正确的标头之外 - 将它们解释为单独的文件并为每个块创建一个新文件...我为新问题 here 创建了一个新问题。

【讨论】:

    猜你喜欢
    • 2012-12-10
    • 1970-01-01
    • 2013-11-13
    • 2014-02-23
    • 2018-10-27
    • 1970-01-01
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多