Meteor-files: How do I change storagePath during upload? I want to use same collection but want to change path based on current module. Is it possible?

Created on 11 Dec 2020  路  3Comments  路  Source: veliovgroup/Meteor-Files

export const Uploads = new FilesCollection({
    collectionName: 'uploads',
    allowClientCode: false,
    storagePath: "/Applications/Ampps/www/elaadmin/public/",
    onBeforeUpload(file) {
        if (/jpeg|png|jpg/i.test(file.extension)) {
            return true;
        } else {
            return "Invalid file format";
        }
    }
});
question

All 3 comments

Hello @pdshah3690,

storagePath can be a function and invoked with fileRef upon upload. See mode details in the Constructor docs

Feel free to close it in case if the issue is solved on your end.

@dr-dimitru It worked. Thanks for this solution.

export const Uploads = new FilesCollection({
    collectionName: 'uploads',
    allowClientCode: false,
    storagePath: function(file) {
        if(file.meta) {
            return "/Applications/Ampps/www/elaadmin/public/uploads/"+file.meta.type+"/";
        }
        return "/Applications/Ampps/www/elaadmin/public/uploads/";
    },
    onBeforeUpload(file) {
        if (/jpeg|png|jpg/i.test(file.extension)) {
            return true;
        } else {
            return "Invalid file format";
        }
    }
});

@pdshah3690 I'm glad you solved it so quickly.


Please support this project with:

Was this page helpful?
0 / 5 - 0 ratings