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

Delete element from collection during upload #263

Closed
Chaosbohne opened this issue Apr 6, 2014 · 13 comments
Closed

Delete element from collection during upload #263

Chaosbohne opened this issue Apr 6, 2014 · 13 comments

Comments

@Chaosbohne
Copy link

Whats the best practise to delete files of a CollectionFS that are still uploading?

Szenario:
I want to have filevalidation (size,type etc.) if a user picks a file. The validation is set with filters inside my collection. Now i pass this file to the collection with an insert, because i havent found a method that gives me the possibilty to make a simple isValidCheck() without uploading.

Now when a user decides to change the image. I had to delete the older image out of CollectionFS and if the image is still uploading there are some ugly error messages in console. The client still tries to upload while he cant because the file was already deleted.

Is there a method to tell the fileObj that i want to stop upload before deleting the image?

Iam using dev-branch.

Whats best practise?

@raix
Copy link

raix commented Apr 6, 2014

use the filters, you could also use the allow/deny rules.

I'm closing this - we are tracking better docs:
cc #213 Add more doc about filters

@raix raix closed this as completed Apr 6, 2014
@aldeed
Copy link
Contributor

aldeed commented Apr 6, 2014

To clarify about pre-upload validation vs. allow/deny:

  • If you use filters, they're checked on the client before starting upload, and then again on the server.
  • If you use allow/deny, these are run only on the server. If you want to save a server trip, you could do the check on the client, too, before calling insert. But 90% of the checks you'll need can be handled with filters, so it's easiest to use that.
  • Even if you use allow/deny, I'm pretty sure the uploading won't begin until the insert is confirmed valid from the server.

In general, I would wait until upload is complete or cancel uploading before deleting a file. I don't think we've tested deleting a file while it's uploading.

@Chaosbohne
Copy link
Author

How to cancel uploading before deleting the file?

@raix
Copy link

raix commented Apr 6, 2014

It should be possible to cancel the upload task and then delete the file?

@raix
Copy link

raix commented Apr 6, 2014

@aldeed btw. we could have the task fail permanently if file not found?

@aldeed
Copy link
Contributor

aldeed commented Apr 7, 2014

@Chaosbohne, FS.HTTP.uploadQueue.cancel();

@Chaosbohne
Copy link
Author

@raix Yes, or deleting the file should imply canceling the upload progress if necessary.
@aldeed Thanks, maybe the cancel() should be mentioned in the docs too. Aswell as a reference from CollectionFS to the Queue.

I came up with the following solution:

// deleteCommand triggered

var fileObj = PostImages.findOne({_id : Session.get('selectedUploadImageId')});

FS.HTTP.uploadQueue.pause();

if(FS.HTTP.uploadQueue.isUploadingFile(fileObj)){
  FS.HTTP.uploadQueue.cancel(fileObj);
}else {
  FS.HTTP.uploadQueue.cancel(fileObj);
  PostImages.remove(Session.get('selectedUploadImageId'));
};      

@raix
Copy link

raix commented Apr 7, 2014

For now FS.HTTP.uploadQueue is a power-queue with the api: https://github.com/CollectionFS/Meteor-power-queue/blob/master/api.md
With added api: https://github.com/CollectionFS/Meteor-cfs-upload-http/blob/master/internal.api.md#FS.File

Its not public api...

@bitomule
Copy link

I'm having the same problem. Is it possible to cancel an upload when a file is removed from collection?

@bitomule
Copy link

@Chaosbohne Does FS.HTTP.uploadQueue.cancel(fileObj); work for you? It doesn't cancel anything for me.

@bitomule
Copy link

bitomule commented Nov 3, 2014

Any update on this? If I cancel a file upload server crashes.

@sksourou
Copy link

hi @bitomule did u find a solution delete during the upload ?

@bitomule
Copy link

I don't remember. I was using a fork that allowed multiple server setups and cancel worked better. I'm not doing a lot of meteor now but I won't use CollectionFS again. I'll try to do something smaller using packages for different parts.

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

5 participants