【问题标题】:Dropzone file not fully processed when calling processFile(File)调用 processFile(File) 时 Dropzone 文件未完全处理
【发布时间】:2015-07-30 05:07:09
【问题描述】:

我在我的 Meteor 应用程序中以编程方式创建了一个 Dropzone,而不是将文件发布到一个 url,我使用 CollectionFS / GridFS 将它们存储在我的 MongoDB 中,并通过迭代 getQueuedFiles 数组为每个文件调用 processFile(File),像这样:

dz.getQueuedFiles().forEach(function(element) {
          Images.insert(element, function(err, fileObj){
            if (err){
              alert("Erreur!");
            } else {
              var imageId = fileObj._id;
              arrayOfImageIds.push(imageId);
              dz.processFile(element);
            }
          })

在文件大小变大之前一切顺利。然后,不知何故,进度条被卡住了一半,并且 processFile 永远不会完成(并且队列没有被清空)。即使我只是隔离 dz.processFile(element) 并注释掉写入文件的数据库,客户端也会挂起。

这是我的 Dropzone 设置:

Template.logoUpload.onRendered(function (){
  Dropzone.autoDiscover = false;

  dz = new Dropzone("form#dropzone", {
    dictDefaultMessage : "DROP YOUR LOGO HERE",
    autoProcessQueue: false,
    addRemoveLinks: true,
    dictRemoveFile: "Delete",
    maxFiles: 2,
    maxFilesize: 5,
    maxThumbnailFilesize: 5,
    accept: function(file, done){
      done();
    },

  init: function() { 
      this.on("addedfile", function(file) {
        Session.set("files", this.files.length);
        if (this.getAcceptedFiles().length > 1) {
          alert("max 2 files allowed");
          this.removeFile(file);
        }
      }),

      this.on("removedfile", function(file) {
        Session.set("files", this.files.length);
      }),

      this.on("queuecomplete", function(file, response){
        console.log("SUCCESFULLY UPLOADED");
        console.log(arrayOfImageIds);
        Session.set("imageIds", arrayOfImageIds);
      })
  }
  });
});

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: mongodb meteor dropzone.js gridfs


    【解决方案1】:

    您是否尝试过增加文件块大小?

    var imageStore = new FS.Store.GridFS("images", {
        chunkSize: 1024*1024  // optional, default GridFS chunk size in bytes (can be overridden per file).
                             // Default: 2MB. Reasonable range: 512KB - 4MB
    });
    
    Images = new FS.Collection("images", {
      stores: [imageStore]
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-28
      • 1970-01-01
      • 1970-01-01
      • 2017-03-08
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 2021-03-18
      相关资源
      最近更新 更多