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)
建议检查一下运行 asp.net core 站点的账户是否对 /var/www/helloworld/upload
目录有写权限
用的supervisor守护启动 dotnet xxx.dll
这是哪个账号?
@microdot: 如果想以 root 帐户运行,需要在 supervisor 的配置文件中添加 user=root
@dudu: 用root是不是不太安全,一般是用什么账号启动,新建一个吗?还是和nginx一样用www-data?
@microdot: 如果不用 root ,那就新建一个账户
chomd -777 /var/www/helloworld/upload/
上传目录不要有执行权限,独写就好