I’m using skipper to upload images and the images keep uploading as being owned by root, not the desired outcome. The sails app is in a sub-folder in user X’s home directory, in which all files are owned by user X. I am running “sudo sails lift” to start the app, so maybe sudo has something to do with it.
Here’s the code for the upload:
req.file('images').upload(function ( error, files ) { if ( error ) { return res.serverError( error ); } return res.json({ message: files.length + ' file(s) uploaded successfully!', files: files }); });
How can I make sure the files are uploaded as user X?
Advertisement
Answer
Sails, or more specifically Node.js, like any webserver, upload file with the owner who started the server. You start sails with sudo, so that’s why. If you want to change that behavior you have 2 options, either running sails with the wanted user, or changing the owner after upload with node fs chown function