Meteor-files: Error: [FilesCollection.uploads] Path "/images" is not writable!

Created on 16 Feb 2017  路  11Comments  路  Source: veliovgroup/Meteor-Files

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?

question

Most helpful comment

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;

All 11 comments

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?

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ck23onGithub picture ck23onGithub  路  3Comments

msgfxeg picture msgfxeg  路  3Comments

rlhk picture rlhk  路  4Comments

sylido picture sylido  路  3Comments

sidkdbl07 picture sidkdbl07  路  4Comments