【问题标题】:asp.net core store images wwwroot dockerasp.net 核心存储图像 wwwroot docker
【发布时间】:2022-01-23 19:08:51
【问题描述】:

我有一个 .net 6 web api。

当用户上传图片时,它应该存储在 wwwroot 文件夹中。

当我运行 docker 时,我从后端收到此错误:

backend    | Unhandled exception. System.IO.DirectoryNotFoundException: /wwwroot\images/
backend    |    at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
backend    |    at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
backend    |    at Program.<Main>$(String[] args) in /RealEstateAPI/Program.cs:line 65
backend exited with code 139

这是我的 Docker 文件:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /
COPY RealEstateAPI/appsettings.json ./RealEstateAPI/AppSettings.json
COPY RealEstateAPI/appsettings.Development.json ./RealEstateAPI/AppSettings.Development.json
COPY RealEstateAPI/wwwroot ./RealEstateAPI/
COPY . .

RUN dotnet restore "RealEstateAPI/RealEstateAPI.csproj"
COPY . .
WORKDIR "/RealEstateAPI"
RUN dotnet build "RealEstateAPI.csproj" -c Release -o /build

FROM build AS publish
RUN dotnet publish "RealEstateAPI.csproj" -c Release -o /publish

FROM base AS final
WORKDIR /
COPY --from=publish /publish .
ENTRYPOINT ["dotnet", "RealEstateAPI.dll"]

如何创建 wwwRoot 卷并在其中存储用户在运行时上传的图像?

  • 卷将在 Heroku 中,因为 docker 映像也将在那里

【问题讨论】:

    标签: asp.net docker heroku wwwroot


    【解决方案1】:

    文件系统在 Heroku 中是短暂的。上传到磁盘只是暂时的。您应该上传到云存储系统(azure blob、AWS S3 等)并将 URL 保存在数据库中的某个位置。

    【讨论】:

      猜你喜欢
      • 2021-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 2019-05-30
      • 2017-07-03
      • 2016-07-26
      相关资源
      最近更新 更多