-
-
Notifications
You must be signed in to change notification settings - Fork 237
can I get a callback for when file upload is completed? #323
Comments
It would be great to have an event for when images were finished thumbing too. |
See Use it in a reactive context. Something like: var fileId = '123456'; // Received from the insert
Deps.autorun(function (computation) {
var fileObj = filesCollection.findOne(fileId);
if (fileObj.hasStored('thumbnailStore')) {
// Thumbnail is available. Do something.
computation.stop();
}
}); |
The latest CFS has some events on the server now. Client events coming soon, or use deps as @sanjo pointed out. filesCollection.on('stored', function (fileObj, storeName) {
// do something
});
filesCollection.on('uploaded', function (fileObj) {
// do something
});
filesCollection.on('error', function (error, fileObj) {
// this will be an upload error; to listen for store errors, listen on the stores themselves
}); Alternatively, the "stored" and "error" listeners can be used directly on a particular store. Listeners on the FS.Collection instance are called for events from all the stores used by the collection. |
It would be nice to have event called when all the files in the queue are uploaded not only one file. Now I have to check in the collection if there are any files without |
I have one more question. What exactly is the callback from Images.insert(fsFile, function(err, image) {
console.log(image.url(), image.isUploaded());
}); When I try calling |
If anyone wants to implement Images.insert(fsFile, function(err, image) {
var cursor = Images.find(image._id);
var liveQuery = cursor.observe({
changed: function(newImage, oldImage) {
if (newImage.isUploaded()) {
liveQuery.stop();
// Call your onUploaded callback here...
}
}
});
}); I can try making pull request but it would be nice if you tell me where is the file responsible for events. |
The insert callback is called when the file document (metadata) is done inserting. (Same as normal collection insert.) So at that point you could store the file's If you really need the |
Ok thanks for clarification. Actually I need information about when uploading is finished. The code which I've posted just works for me. I could try making client side events but I would need some information. I see that there are events defined for both environments. So is the only thing that needs implementation to hook into update method of collection and check whether file has already been uploaded? |
Actually there is FS.Collection is great package and I would like to work on it. There are some bugs and comments like TODO, FIXME, XXX etc. It's a lot like work in progress :) but together we can make it better. Many things needs clarification and refactoring. |
@jagi, yeah, that emits when the client is finished chunking and sending the chunks, but Our plan was to try to make a generic client/server events package and use that. We already use Anyway, if someone can create that package/feature, then it should be easy to get the rest of the CFS events in place. There are a lot of cases where we want to emit the event on the server but listen on the client, including "uploaded". |
I realized that what we're planning to do, described in my last comment, is very similar to @arunoda's streams package. My thought was to do something like @arunoda, it does not look like you're maintaining the streams pkg anymore? What do you think about folding that feature into |
If you guys are doing that I'd suggest to do it as a separate project. I think |
I think ddp will support triggering events on the server and have it populate to clients? Agree, the eventemitter package should remain as slim/stable as possible, I've started to use it a lot its a very general feature - that said I'm thinking about adding something like The package we should create for this is "observable streams" - this could in theory be used for events and data. #216 https://github.com/Reactive-Extensions/RxJS http://msdn.microsoft.com/en-us/data/gg577609.aspx http://reactivex.io/ The reason for stuff like this is the async nature - I've written a File handling is heavy stuff so if we can have throttles observable streams handling up/downloads we could make sure theres time for the UI and GC = better user experience. Theres some things to think about, |
But is it possible using DDP to call some method from the server to the client? I think it's not possible right now. If it will be available in the future, do you know when the meteor core team is planing to implement such feature? I agree that having possibility to invoke events in both directions would be nice. |
Odd, the DDP v2 card is removed from their trello card - maybe @glasser knows about this. If we want we could implement events from/to server via sub/pub and methods - it would make sense to be able to subscribe to certain events - maybe via an in memory database on the server or the fileRecord. Maybe have an observer to event emitter package, |
Hello, Do we have any news on this ? Jagi's code snippet looks like the fastest option for me at this time but I am wondering how the server side events (uploaded, stored, etc...) are as useful as it could be on client side. I mean, if I need to upload several files, wait for them to be all uploaded and then trigger some processing on server side, the mechanism between client and server would be quite complicated unless CollectionFS.insert could be called on server side. At least, if we could listen to these events on client side, the whole logic would stay in client code and stay simple but imho, this code should be server side. |
@aldeed Seems like filesCollection.on('stored') is producing some errors for me:
Are there any docs to help debug this? |
@jagi I don't know if somebody already found the correct way of doing this but I tried this.
if you see I checked for |
@ncubica whatever works for you :). There are some errors in CollectionFS like for example the |
Hey all, so I'm trying to write a http://orionjs.org/docs/filesystem-providers For my purposes,
Just to confirm, in CollectionFS there is no way to get the URL of the file right after it is finished uploading, right?
|
@fuzzybabybunny I added functions that add callback for file upload per store, in the PR #782 you can use it. |
Thanks. Hopefully the PR gets accepted soon as well. |
+1 would like to see that PR merged.
|
+1 |
@jurgenfink what's your collection fs and meteor version? Mine keeps telling me error. |
@hamxiaoz Good Morning Andrew,
Server (example:
Client (example:
(Side-Note: I repeat same Client (example:
Client and Server (example:
Hope this helps |
So after more than 1.5 years, this is still like this with hacks ... |
Being unable to get image (file) url immediately after upload is finished, i.e. not knowing when upload is finished, is a deal breaker. |
Love CFS, hate the difficulty in getting anything to work without hacks / intervals galore. |
Try to this: let fileObj = Files.findOne(_id);
fileObj.on('stored', Meteor.bindEnvironment(function() {
// do something
})); |
please where i have to put this trigger? filesCollection.on('stored', function (fileObj, storeName) |
It's working only on server side // Client
Template.some_template.events({
'change #file'( event ) {
FS.Utility.eachFile(event, function ( file ) {
Images.insert(file, function (err, fileObj) {
if (err) throw err;
Meteor.call('someMethod', fileObj._id);
});
});
}
});
// Server
Meteor.methods({
someMethods( fileId ) {
var file = Images.findOne(fileId);
file.once('stored', Meteor.bindEnvironment(function() {
// do something
}));
}
}); On client you may use isUploade |
My version for catch id's during multiple upload...
|
uploaded event worked for me. |
No description provided.
The text was updated successfully, but these errors were encountered: