【发布时间】:2022-01-26 19:31:40
【问题描述】:
我正在上传用户图像并将图像存储在文件夹中,并将它们的名称存储在数据库中
-
通过 Angular 完成图片上传
-
图像存储到文件夹和数据库由 dotnet core api 完成
两种操作都可以正常工作,但我无法在站点中显示存储的图像。
SQL 数据库存储图片网址
要在客户端访问此图像,我在 angular 中使用以下内容
Component.html 文件
<img [src]="createImgPath()" alt="profile picture" 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
如果我直接尝试在浏览器中访问它而不是我得到以下错误
仍然没有得到什么问题。这种方法有什么问题。
【问题讨论】:
-
localhost:9529 是您的服务器基础 url 还是 Angular 的?
-
相对于 web 根目录的资源文件夹在哪里。您是否启用了静态文件-例如
UseStaticFiles()- 见docs.microsoft.com/en-us/aspnet/core/fundamentals/… -
@yazantahhan 它的 web api url
-
@SpruceMoose 我已经添加了我存储图像的文件夹结构的屏幕截图,请参阅更新后的帖子。
标签: angular asp.net-core file-upload