Closed chrschae closed 2 years ago
Hello,
It depends from how do you want to serve files? Is is public
collection?
storagePath
and namingFunction
FilesCollection constructor optionsdownloadRoute
and/or public
optionsThanks 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
},
@chrschae please test your implementation on the latest v2.2.0
release
Feel free to close it in case if the issue is solved on your end.
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.
@chrschae please try v2.2.1
hope that it won't be an issue anymore, let me know
@chrschae did the latest release solve this issue for you?
@dr-dimitru sorry for answering so late. Yes, the problem is resolved. Thank you very much!
@chrschae great! Thank you for feedback
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!