0

I have tried to run function to upload the file to the assets folder in the server. It work on my mac, but when I run it on CentOS 7 server, the error of mkdir permission denied occured.

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

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

I have already set the permission folder, as you can see:

drwxrwxrwx.   2 root root   4096 May  6 12:49 assets

and to try execute it from folder app, already tried changing the dirname line into

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

but still, the same error of EACCESS permission denied mkdir to the folder /images persist . Is there any workaround to let sailsjs apps generate a sub folder inside /assets folder without getting this error?

Zuzu Softman
  • 468
  • 4
  • 15

1 Answers1

0

Currently, it seems the OS does not allow sailsjs function req.file().upload to make a directory. So, the possible workaround is by using File System (fs) module to access low level operation for handling the mkdir task, then after the directory created, call the req.file().upload.

Zuzu Softman
  • 468
  • 4
  • 15