Meteor-Community-Packages/Meteor-CollectionFS

How to cancel upload queue ?

Opened this issue · 0 comments

Hello,
I have problems with cancelling file uploads.
Here is my helper button :

'click .btnCancel': function(e, instance) {
      e.preventDefault();
      if (FS.HTTP.uploadQueue.files && FS.HTTP.uploadQueue.files.attachments){
        console.log("Queue is running : ", FS.HTTP.uploadQueue.isRunning()); //ok returns true;
        const attachmentIdsOfFilesUploading = Object.keys(FS.HTTP.uploadQueue.files.attachments); 
        console.log("attachmentIdsOfFilesUploading : ", attachmentIdsOfFilesUploading); //return  ["attachmentId1", "attachmentId2"]
        FS.HTTP.uploadQueue.cancel();
        console.log("Queue is running : ", FS.HTTP.uploadQueue.isRunning()); //ok return false;
        Meteor.call("deleteAttachments", attachmentIdsOfFilesUploading, function(err){ 
          //This performs Attachments.remove({'_id: {$in:  ["attachmentId1", "attachmentId2"]}'})
          if (err){
            console.error(err); //Here we have error because collection FS is trying to remove the file (unlink) but as the file is not finished upladoed, it fails
            toastr.error(err.reason);
            return;
          }
          toastr.info(TAPi18n.__("Upload queue has been cancelled"));
          window.location.reload(); //this is needed of collection FS crashes, the queue continue with some chunks...
        });
      }
    },

Thanks if you guys know what to do.