veliovgroup / Meteor-Files

🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
https://packosphere.com/ostrio/files
BSD 3-Clause "New" or "Revised" License
1.11k stars 166 forks source link

How namingFunction was changed from 2.0.1 to 2.2.1 ? Uploading files does not work. #847

Closed xet7 closed 2 years ago

xet7 commented 2 years ago

Hi, after upgrade, uploading files does not work:

ostrio:files    upgraded from 2.0.1 to 2.2.1

I'm getting this error:

W20220815-14:33:39.476(3)? (STDERR)     at packages/cfs_http-methods.js:631:30
I20220815-14:34:08.920(3)? Exception while invoking method '_FilesCollectionStart_attachments' TypeError: Cannot read property 'replace' of undefined
I20220815-14:34:08.921(3)?     at FilesCollection.namingFunction (models/attachments.js:44:48)
I20220815-14:34:08.921(3)?     at FilesCollection._prepareUpload (packages/ostrio:files/server.js:990:26)
I20220815-14:34:08.921(3)?     at MethodInvocation.FilesCollection._methods.<computed> (packages/ostrio:files/server.js:849:33)
I20220815-14:34:08.922(3)?     at packages/check/match.js:118:15
I20220815-14:34:08.922(3)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1257:12)

How this namingFunction should be changed?

https://github.com/wekan/wekan/blob/master/models/attachments.js#L44

WeKan Open Source kanban https://wekan.github.io currently uses Meteor 2.7.3, Node 14.20.0 and MongoDB 5.x. WeKan has features to move attachments from MongoDB to filesystem and back.

xet7 commented 2 years ago

Related https://github.com/veliovgroup/Meteor-Files/issues/842

xet7 commented 2 years ago

Hmm, I read a little from docs and tried just commenting out that custom namingFunction in WeKan code. Uploading seems to work now.

@mfilser could comment, did I do anything stupid here.

xet7 commented 2 years ago

It seems that after that change existing files do not work, because filename does not include text original.

dr-dimitru commented 2 years ago

Hello @xet7,

xet7 commented 2 years ago

From https://github.com/wekan/wekan/commit/7c619859fcb6a609581adc8f09c7937b7c2efcc4#commitcomment-81295578

Hello @xet7
I've seen https://github.com/veliovgroup/Meteor-Files/issues/847 And I'd like to jump in order to help resolving this one. Could you explain initial purpose of custom namingFunction() hook? Since you have commented it out — it works without it in the expected way?

Commenting out only works for new attachments. Problem is, that this code, that tries to generate filename without extension, does not get filename from opts.meta.name anymore at all, replace function does not work to remove extension:

    const filenameWithoutExtension = opts.meta.name.replace(/(.+)\..+/, "$1");

I did try:

With this code, it tries to generate new filename with fileid-original-filenameWithoutExtension:

const ret = opts.meta.fileId + "-original-" + filenameWithoutExtension;

Problem is, when all that namingFunction() code is commented out, all old existing attachments have wrong URL, and are not visible at WeKan kanban board at all.

dr-dimitru commented 2 years ago

@xet7

  1. I don't see how namingFunction may affect files uploaded before lib update. It runs only in writing/uploading methods
  2. Let me know output of console.log(opts) inside namingFunction
xet7 commented 2 years ago

@dr-dimitru

Error message of namingFunction is at top first of this issue. That error has come after upgrading Meteor-Files from 2.0.1 to 2.2.1.

xet7 commented 2 years ago

Hmm, just a moment, I'll try adding console.log(opts)

dr-dimitru commented 2 years ago

From the constructor docs

Function which returns String. Use it to create nested directories in the storage folder. Note: file extension appended to returned value

meaning it will force to append and handle file's extension on its own. And you want uploaded files have no extension?

xet7 commented 2 years ago

Fixed at https://github.com/wekan/wekan/pull/4638