Skip to content
This repository has been archived by the owner on Mar 14, 2019. It is now read-only.

How to cancel upload queue ? #1038

Open
dokithonon opened this issue Aug 21, 2018 · 0 comments
Open

How to cancel upload queue ? #1038

dokithonon opened this issue Aug 21, 2018 · 0 comments

Comments

@dokithonon
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant