I'm using CollectionFS to store files uploaded from my meteor app. I'm using the cfs-filesystem package to save my files using the local filesystem.
Right now, when I upload a file, it gets saved to ~/uploads/images-h9jWnALqSZMpAX4h4-IMG_3737.JPG
I have an existing filesystem structure that I need to work with and we need the files to be easy to traverse by hand if necessary.
Suppose I want to customize that path to be something like this ~/uploads/jaredtmartin/IMG_3737.jpg. And when a different user uploads, it goes to a new folder with his name, for example, ~/uploads/suzyq/IMG_1234.jpg. Can that be done? If not, where can I dig in to modify the code to make it happen?
You can use the fileKeyMaker, see here
var imageStore = new FS.Store.FileSystem("images", {
fileKeyMaker: function (fileObj) {
// Lookup the copy
var store = fileObj && fileObj._getInfo(name);
// If the store and key is found return the key
if (store && store.key) return store.key;
// TO CUSTOMIZE, REPLACE CODE AFTER THIS POINT
var filename = fileObj.name();
var filenameInStore = fileObj.name({store: name});
// If no store key found we resolve / generate a key
return fileObj.collectionName + '-' + fileObj._id + '-' + (filenameInStore || filename);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With