dropzone.js如何在服务器响应后向块添加新参数?

时间:2019-01-23 21:28:22

标签: javascript dropzone.js dropzone

我已经使用Dropzone.js 5.5和Laravel 5.7设置了图像上传。由于我的共享主机帐户出现问题,因此我决定使用块上传。我希望能够创建一个相册并上传大约30张图像,总共100 Mb,但通常会以20Mb的速度崩溃。激活Chunking后,我直接遇到最明显的问题,发布到store方法意味着
每次创建一个新专辑,所以我认为最好创建一个专辑,返回AlbumId并将其添加到下一个块中。因此,如果我在参数中执行console.log(chunk),则会得到以下信息:

enter image description here

所以我在文件xhr:XMLHttpRequest Response中获得了专辑ID。我如何才能将其取出并添加到我的params块函数中?

Dropzone.options.myAwesomeDropzone = { 
  autoProcessQueue: false,
  totalMaxsize: 100,
  parallelUploads: 1,  // since we're using a global 'currentFile', we could have issues if parallelUploads > 1, so we'll make it = 1
  maxFilesize: 10,   // max individual file size 1024 MB
  chunking: true,      // enable chunking
  forceChunking: true, // forces chunking when file.size < chunkSize
  parallelChunkUploads: false, 
  chunkSize: 1000000,  // chunk size 1,000,000 bytes (~1MB)
  retryChunks: true,   // retry chunks on failure
  retryChunksLimit: 10, // retry maximum of 3 times (default is 3)
  maxFiles:30,
  timeout: 600000, 
  paramName:'file',
  acceptedFiles: ".jpg,.jpeg,.png",
  previewTemplate: previewTemplate,
  previewsContainer: "#previews", // Define the container to display the previews
  clickable: ".fileinput-button", // Define the element that should be used as click trigger to select files.
  countImages:0,

params: function (files, xhr, chunk) {

    if (chunk) {
            return {
                dzAlbumID: HERE SHOULD BE MY RETURNED ALBUM ID
                dzUuid: chunk.file.upload.uuid,
                dzChunkIndex: chunk.index,
                dzTotalFileSize: chunk.file.size,
                dzCurrentChunkSize: chunk.dataBlock.data.size,
                dzTotalChunkCount: chunk.file.upload.totalChunkCount,
                dzChunkByteOffset: chunk.index * this.options.chunkSize,
                dzChunkSize: this.options.chunkSize,
                dzFilename: chunk.file.name,

            };
        }
    },

0 个答案:

没有答案