使用Dropzone分段上传文件仅上传最后一部分(块)

时间:2019-05-20 09:42:08

标签: amazon-web-services amazon-s3 multipartform-data dropzone.js

我正在尝试使用Dropzone js分段上传大文件(视频)到Wasabi(AWS副本)。我得到的错误是仅上传最后一块。而且我不知道为什么,但是dropzone上一次调用不会编译文件。我尝试了不同的方法,但没人对我有用。这是我的dropzone对象:

var dropzone = new Dropzone('#video-dropzone', {
            previewTemplate: document.querySelector('#preview-template').innerHTML,
            parallelUploads: 2,
            thumbnailHeight: 120,
            thumbnailWidth: 120,
            method: 'POST',
            paramName: "file",
            autoProcessQueue: false,
            timeout: 7200000,
            maxFilesize: 500000,
            chunking: true,
            parallelChunkUploads: false,
            chunkSize: 100000000, {# 1000000000   1GB per part #}
            params: function (files, xhr, chunk) {
            if (chunk) {
                return {
                    UploadId: chunk.file.upload.uuid,
                    PartNumber: chunk.index,
                    TotalFileSize: chunk.file.size,
                    CurrentChunkSize: chunk.dataBlock.data.size,
                    TotalChunkCount: chunk.file.upload.totalChunkCount,
                    ChunkByteOffset: chunk.index * this.options.chunkSize,
                    ChunkSize: this.options.chunkSize,
                    Filename: chunk.file.name,
                };
            }
        },
            init: function () {
                thisDropzone = this;
                {# When a file is added, we need to put the fields of the video, #}
                {# so we show a video create form #}
                thisDropzone.on('addedfile', function (file) {
                    thisDropzone.options.url = $("#video-dropzone").attr("action");
                    $.confirm({
                        title: "{% trans 'Video Create' %}",
                        content: 'url:{% url 'video-create' %}',
                        useBootstrap: false,
                        theme: 'material',
                        buttons: {
                            create: function () {
                                {# If the title is empty, you can't create it #}
                                if ($("#id_title").val() == "") {
                                    $("#id_title").addClass("is-invalid");
                                    return false;
                                }
                                {# Creation of the video fields #}
                                let create_video = video_create(file);

                                {# If all fields has been created correctly,#}
                                {# the generate a signature and launch the queue #}
                                if (create_video.status == 200) {
                                    file.customName = create_video.data.filename;

                                    generar_signature(file);

                                    {# When all fields are correct, the dropzone can start#}
                                    {# to upload the files #}
                                    thisDropzone.processQueue();
                                }

                            },
                            cancel: function () {
                                {# Removes the file if you click cancel #}
                                thisDropzone.removeFile(file);
                            }
                        }
                    });

                });

它正确地将文件分块,但是在存储中完成后,我只能看到最后一部分

1 个答案:

答案 0 :(得分:0)

这是因为每次调用块时都会调用API。 因此,它仅存储最后一个块。 您必须将每个块存储到byteArray(全局)中并进行相应处理