Agustín
Agustín

Reputation: 1546

Upload file from Angular JS to Sails JS

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?

Upvotes: 2

Views: 803

Answers (2)

Mariusz Wiazowski
Mariusz Wiazowski

Reputation: 2446

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...).

Upvotes: 6

Erick Arroyo
Erick Arroyo

Reputation: 142

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

Upvotes: 0

Related Questions