On local, I've set my uploadPath to '/images' as instructed. However Meteor gives me the follow error on build:
Error: [FilesCollection.uploads] Path "/images" is not writable!
Does the folder need to be created first? Where exactly?
Hi @jetlej ,
Does the folder need to be created first?
Yes, if parent directory tree is writable by user which runs meteor/node.js process
Where exactly?
Wherever you want, first / means your FS root
I'm on OSX. Do I need to change permissions?
What do you mean by FS root?
Thanks so much for your help!
What do you mean by FS root?
I'm on OSX. Do I need to change permissions?
Most OSs shares similar vision for permissions, users and groups. I'm personally prefer /data directory in FS root, most of this is described in FAQ
Here is /data/uploads with very open permissions, but good for dev:
mkdir -p /data/uploads
chmod -R 777 /data
I ran those commands and tried setting 'storagePath' to '/data' and to '/data/uploads' and no media is being added to that folder upon upload :/
set debug: true into FilesCollection Constructor, you should see where files going to be written upon meteor start
Hello @jetlej ,
Any news from your end?
Hi @jetlej
Have you figured out how to setup storage path?
For relative storage you could use process.env.PWD. The following code uploads files to METEOR-PROJECT-ROOT/uploads
ES6 code
import { FilesCollection } from 'meteor/ostrio:files';
const Images = new FilesCollection({
collectionName: 'Images',
allowClientCode: false,
storagePath: () => {
return `${process.env.PWD}/uploads`;
},
onBeforeUpload: (file) => {
if (file.size > 10485760) {
return 'Please upload image, with size equal or less than 10MB.';
}
if (!/png|jpg|jpeg/i.test(file.extension)) {
return `${file.extension}'s files are not allowed for upload.`;
}
return true;
},
});
export default Images;
Here is also useful lib for working with relative paths - https://github.com/VeliovGroup/Meteor-root
Sorry for the late reply! I had to create a folder in the root directory of my computer. On my Mac, that was the 'Macintosh HD' folder, even above the user folder.
@jetlej thank you for update
Most helpful comment
For relative storage you could use process.env.PWD. The following code uploads files to METEOR-PROJECT-ROOT/uploads
ES6 code