Attachment filename contains now the filename of the uploaded file

This commit is contained in:
Martin Filser 2022-04-01 23:09:59 +02:00
parent 44fd652b05
commit 0fcfd8e168
2 changed files with 26 additions and 11 deletions

View file

@ -11,6 +11,13 @@ Attachments = new FilesCollection({
debug: false, // Change to `true` for debugging
collectionName: 'attachments',
allowClientCode: true,
namingFunction(opts) {
const filenameWithoutExtension = opts.name.replace(/(.+)\..+/, "$1");
const ret = opts.meta.fileId + "-" + filenameWithoutExtension;
// remove fileId from meta, it was only stored there to have this information here in the namingFunction function
delete opts.meta.fileId;
return ret;
},
storagePath() {
if (process.env.WRITABLE_PATH) {
return path.join(process.env.WRITABLE_PATH, 'uploads', 'attachments');