简体   繁体   English

SailsJS船长以root身份上载文件,如何以应用程序所有者身份上载?

[英]SailsJS skipper uploading files as root, how do I upload as the app's owner?

I'm using skipper to upload images and the images keep uploading as being owned by root, not the desired outcome. 我正在使用船长上载图像,并且这些图像继续由root拥有,而不是期望的结果。 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. sails应用程序位于用户X的主目录的子文件夹中,该目录中的所有文件均由用户X拥有。我正在运行“ sudo sails lift”以启动该应用程序,因此sudo可能与此有关。

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? 如何确保文件以X用户身份上传?

Sails, or more specifically Node.js, like any webserver, upload file with the owner who started the server. Sails,或更具体地说,像任何Web服务器一样,Node.js与启动服务器的所有者一起上传文件。 You start sails with sudo, so that's why. 您从sudo开始航行,所以这就是原因。 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 如果要更改该行为,则有2个选项,要么与所需用户一起运行,要么在使用node fs chown函数上传后更改所有者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM