我正在上傳用戶影像并將影像存盤在檔案夾中,并將它們的名稱存盤在資料庫中
由角度完成的影像上傳
由 dotnet core api 完成的影像存盤到檔案夾和資料庫
兩種操作都可以正常作業,但我無法在站點中顯示存盤的影像。
SQL 資料庫存盤影像 url

要在客戶端訪問此影像,我正在使用以下角度
組件.html 檔案
<img [src]="createImgPath()" alt="相對影像 URL" style="width:60px; height:60px;">
.ts 檔案
public createImgPath = () => {
debugger;
if(this.studentPriviewImage==null)
{
return this.fallback;
}else{
console.log(data1);
return environment.baseUrl this.studentPriviewImage.filepath1;
}
}
回傳http://localhost:9529/Resources/Group/student_Photo/11/3/18/3_20220127002626AM.png
如果我直接嘗試在瀏覽器中訪問它而不是我收到以下錯誤

存盤影像檔案的我的解決方案檔案夾結構。

仍然沒有得到什么問題。這種方法有什么問題。
uj5u.com熱心網友回復:
如果要在 Web 根目錄之外提供檔案,則需要在 StartUp.cs 中添加以下配置:
app.UseStaticFiles();
...
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Resources")),
RequestPath = "/Resources"
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422414.html
標籤:
