我可以创建文件夹,但不能向其中写入文件

I can create folders, but cannot write files to them

我目前正在编写一个 Asp.Net / Angular 应用程序,它应该从 Windows 网络驱动器读取 PDF 并向其写入。该应用程序托管在 Linux 服务器上的 Linux Docker 容器中。该应用程序可以创建文件夹,但只要将 PDF 保存在驱动器上,我就会收到 UnauthorizedAccessException:

System.UnauthorizedAccessException: Access to the path '/path/to/file/document.pdf' is denied.
 ---> System.IO.IOException: Permission denied

我正在像这样在 docker-compose.yml 中安装网络驱动器:

version: '3'

services:
    MyService:
        image: registry.my-registry.de/group/my-service:latest
        privileged: true
        ports:
        - "9191:443"
        restart: always
        environment:
        - ASPNETCORE_ENVIRONMENT=Production
        - ASPNETCORE_URLS=https://+:443
        - ASPNETCORE_Kestrel__Certificates__Default__Password=
        - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
        volumes:
        - ./ssl/my-certificate.p12:/https/aspnetapp.pfx
        - my-volume:/path/to/file:rw
volumes:
    my-volume:
        driver_opts:
            type: cifs
            o: username=MyUser,password=password,domain=MyDomain,rw,iocharset=utf8,file_mode=0777,dir_mode=0777
            device: "//hostip/path/to/targetfolder"

MyUser是AD账号,对目标文件夹有读写权限。当我通过 bash 终端进入 docker 终端并导航到安装的驱动器时,我能够创建一个文件和一些文本。

将文档写入驱动器的方法如下所示:

[HttpPost]
public async Task<ActionResult<File>> CreateAsync([FromForm] IFormFile file) // file was sent from the Angular front end
{
/*...*/
    using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
    {
        await file.CopyToAsync(stream); //Exception occurs here
    }
/*...*/
}

此代码在我的测试环境 (CentOS 7) 中运行,没有任何问题。我错过了什么吗?

好的,我尝试了一些东西并且它起作用了。我没有使用 CopyToAsync,而是将文件转换为字节数组,然后将其写入磁盘:

using (var ms = new MemoryStream())
using (var fs = System.IO.File.Create(filePath))
{
    await file.CopyToAsync(ms);
    await fs.WriteAsync(ms.ToArray());
}

我不知道为什么会这样,但我花了几天时间才弄明白,所以我接受了。