[英]Sailsjs permission denied creating folder when uploading a file
I have tried to run function to upload the file to the assets folder in the server.我尝试运行 function 将文件上传到服务器中的资产文件夹。 It work on my mac, but when I run it on CentOS 7 server, the error of mkdir permission denied occured.它可以在我的 mac 上运行,但是当我在 CentOS 7 服务器上运行它时,出现了 mkdir 权限被拒绝的错误。
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
行更改为
dirname: sails.config.appPath + 'assets/images'
but still, the same error of EACCESS permission denied mkdir to the folder /images
persist.但仍然存在相同的 EACCESS 权限错误,拒绝 mkdir 到文件夹/images
。 Is there any workaround to let sailsjs apps generate a sub folder inside /assets
folder without getting this error?是否有任何解决方法可以让sailsjs 应用程序在/assets
文件夹中生成一个子文件夹而不会出现此错误?
Currently, it seems the OS does not allow sailsjs function req.file().upload
to make a directory.目前,操作系统似乎不允许sailsjs function req.file().upload
创建目录。 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
.因此,可能的解决方法是使用文件系统( fs
)模块访问处理mkdir
任务的低级操作,然后在创建目录后调用req.file().upload
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.