Is there a posibility to install a server side hook to handle things after uploading an image? For example when the user changed his profile picture, I want to update the user document and some othe documents that include the profile picture.
I think the workaround doing a second call from client is insecure and could cause inconsistency.
Don’t know if it works with CollectionFS, but maybe you can try it:
I already tried collection-hooks but unfortunaltely they doesn’t work with FS.Collection objects.
Mhh okay, and what about observers?
if(Meteor.isServer) {
MyCollection.find().observe({
added: function(item) {
// …
}
}
1 Like
This is what I’m using. It’s from a CSV importer which runs a server side function on the CSV after import. You should be able to adapt it for your needs.
both/collections/imports.js
const importCSV = function(fileObj, readStream, writeStream) {
if (Meteor.isServer) {
// Do stuff with fileObj
}
};
const Imports = new FS.Collection('imports', {
stores: [
new FS.Store.FileSystem('imports', {
path: '/Users/tim/code/personal/leadiq-uploads/imports',
transformWrite: importCSV
})
]
});
_.extend(Collections, { Imports });
1 Like
It absolutely does, but you should access it like this:
If your collection is called Files:
Files = new FS.Collection("files", {
stores: [fileStore]
});
A collection hook for this would be:
Files.files.after.insert(function(userId, doc){
//Something something darkside
})
We’re using this in production and would recommend this approach as well.
1 Like
Thank you guys for your help.