.net core 在linux下上传文件没有权限

2019-01-03 00:14发布

using (var stream = new FileStream(filename, FileMode.Create)) {
    upFile.CopyTo(stream);
}

 

在windows下测试是没问题的。

Access to the path '/var/www/helloworld/upload/xxx.jpg' is denied.

System.UnauthorizedAccessException: Access to the path '/var/www/helloworld/upload/xxx.jpg' is denied. ---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)

2条回答
等我变得足够好
2楼-- · 2019-01-03 00:25

chomd -777 /var/www/helloworld/upload/

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-03 00:40

建议检查一下运行 asp.net core 站点的账户是否对 /var/www/helloworld/upload 目录有写权限

查看更多
登录 后发表回答