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

Using FileID to set filesystem path #842

Closed chrschae closed 2 years ago

chrschae commented 2 years ago

Hello, Im wondering if this package supports subdirectories - I would like to have a structure like

project_files / projectID / file1 project_files / projectID / file2

I managed to save the files by calling the write function on the server like

const _addFileMeta = { fileName: filename, type: mimeType, fileId: "project_documents/48979DF2-7214-EC11-8EB6-00155D647A28" + path.parse(filename).name, meta: { type : FILE_TYPE_PROJECT, crmId : "48979DF2-7214-EC11-8EB6-00155D647A28", userId: user._id } }; Files.write(buffer, _addFileMeta, function (_uploadError, _uploadData) { ....

The problem with this approach is that the .link() method seems to be broken now - i get a link back like http://localhost:3000/cdn/storage/files/project_documents/48979DF2-7214-EC11-8EB6-00155D647A28/test-img3/original/project_documents/48979DF2-7214-EC11-8EB6-00155D647A28/test-img3.jpg?download=true

The file on the filesystem got saved like it should, only problem i have is the link not working now - i guess this isnt supported? Maybe there is another way to achieve a subdirectory structure?

Thanks in advance!

dr-dimitru commented 2 years ago

Hello,

It depends from how do you want to serve files? Is is public collection?

  1. For custom name on FS see storagePath and namingFunction FilesCollection constructor options
  2. For custom name/URL upon download use downloadRoute and/or public options
chrschae commented 2 years ago

Thanks for the answer.

The URL of the download is not really relevant for me, but i want the files organized in subdirectories. I am using namingFunction now and on the Server it works with the Files.write() function as expected ! Files are saved in my subdirectories, and the download link is working (not broken) as well.

However, on the client, when I insert into the Collection via Files.insert(), the file is saved in another location e.g. in project_documents-projectID-filename instead of project_documents/projectID/filename

this is my namingFunction

namingFunction:(file)=>{
        const path = require('path');
        if(file.meta?.type === FILE_TYPE_PROJECT){
            let fileName = file.fileName ? path.parse(file.fileName).name : path.parse(file.name).name ;
            return `${FILE_TYPE_PROJECT_DIR}/${file.meta.crmId}/${fileName}`
        }else return file.fileName
},
dr-dimitru commented 2 years ago

@chrschae please test your implementation on the latest v2.2.0 release

dr-dimitru commented 2 years ago

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

chrschae commented 2 years ago

Hello! Thank you, it works! I found a bug though. If call Files.write() and the directory doesn't exist, it will throw an error. On Files.insert(), it will create the directory instead.

image

dr-dimitru commented 2 years ago

@chrschae please try v2.2.1 hope that it won't be an issue anymore, let me know

dr-dimitru commented 2 years ago

@chrschae did the latest release solve this issue for you?

chrschae commented 2 years ago

@dr-dimitru sorry for answering so late. Yes, the problem is resolved. Thank you very much!

dr-dimitru commented 2 years ago

@chrschae great! Thank you for feedback