2

I'm new with Sails and Im trying to upload a file using Angular in the frontend side. This is my FileController

module.exports = {
    upload: function  (req, res) {
        req.file('file').upload({
            dirname: require('path').resolve(sails.config.appPath, '/assets/images')
        },function (err, uploadedFiles) {
            if (err) return res.negotiate(err);

            return res.json({
                message: uploadedFiles.length + ' file(s) uploaded successfully!'
            });
        });

    }
};

and I'm getting this error trying to create a directory to save the file:

Sending 500 ("Server Error") response: 
 Error: EACCES, mkdir '/assets' { [Error: EACCES, mkdir '/assets'] errno: 3, code: 'EACCES', path: '/assets' }

and if I delete that line with the dirname, I think its supposed to save it into a temp folder by default. I tried that, I got the success message, but no temp folder is created. any ideas?

2 Answers 2

6

I had the same problem. You have to change this line:

dirname: require('path').resolve(sails.config.appPath, '/assets/images')

with this one:

dirname: sails.config.appPath + '/assets/images'

The problem was that you needed root permissions because Sails was creating a folder in you home directory (and not in your app folder...).

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure you got the right permisions to the folder that you want to upload the files, try sudo chmod 775 assets/

2 Comments

same problem, and if I delete that line I think its supposed to save the file in a temp folder by default, so I tried that, I got the success message, but there is no temp folder
Also make sure that the file that is running the server got the right permissions too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.