Dropzone file not fully processed when calling pro

2019-07-31 17:35发布

问题:

I'm creating a Dropzone programmatically in my Meteor application and instead of posting Files to a url I'm storing them inside my MongoDB with CollectionFS / GridFS and call processFile(File) for each one by iterating over the getQueuedFiles array, like so:

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);
            }
          })

All goes well until the File sizes are bigger. Then, somehow the progress bar gets stuck halfway and the processFile is never finished (and the queue not emptied). Even when I just isolate the dz.processFile(element) and comment out the DB writing the file hangs in the client.

This is my Dropzone setup:

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);
      })
  }
  });
});

Anyone have an idea how to solve this?

回答1:

Have you tried increasing the file chunk size?

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]
});