Return .NET Core API 图像(存储在 wwwroot 目录下) link 到客户端

Return .NET Core API image (stored under wwwroot directory) link to client

我的 .NET Core API 将上传的图片存储在 /wwwroot/uploads/images/

我需要在我的 Ionic 应用程序中显示这些图像,所以我需要一个 URL 指向像这样的图像:http://hostname:5000/uploads/images/image.png,所以我可以在我的应用程序中做一些事情,例如:

<img src="http://hostname:5000/uploads/images/image.png" />

事实是,当我将此 URL 放入浏览器时,它 return 是一个 404(未找到)错误。

哪个是正确的 URL 我如何 return 它来自 API?

提前致谢。

在 .net 核心中,您必须启用静态文件。您可以通过在 Startup class.

的 Configure 方法中将 UseStaticFiles() 添加到应用程序构建器来实现

Startup.cs:

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles();
}

Reference