C# 如何在我的angular应用程序中使用.net core API上传的文件?

C# 如何在我的angular应用程序中使用.net core API上传的文件?,c#,angular,.net-core,C#,Angular,.net Core,我在Angular应用程序中显示图像时遇到问题。 这在我的profile.ts和profile.html页面中 publicCreateImgPath=(服务器路径:字符串)=>{ 返回`http://localhost:63040/${serverPath}`; } 这是一个非常愚蠢的打字错误。在var folderName中,我使用“userImages”,而不是“usersImages”。很抱歉给大家添麻烦。我想您应该以blob的形式返回文件。因为您无法将图像作为JSON发送到angul

我在Angular应用程序中显示图像时遇到问题。 这在我的profile.ts和profile.html页面中

publicCreateImgPath=(服务器路径:字符串)=>{
返回`http://localhost:63040/${serverPath}`;
}

这是一个非常愚蠢的打字错误。在var folderName中,我使用“userImages”,而不是“usersImages”。很抱歉给大家添麻烦。

我想您应该以blob的形式返回文件。因为您无法将图像作为JSON发送到angular。首先,将您的后端代码更改为以下内容:

var folderName = Path.Combine( "userImages", fileName);
return new FileStream(folderName , FileMode.Open, FileAccess.Read);
然后将
[HttpGet]
更改为
[HttpPost]


我不知道如何将图像文件发送到后端,但我认为您可以通过这些更改解决问题。

您是否为静态文件服务配置了
userImages
文件夹?是的,因为userImages位于我使用的wwwroot文件夹中:app.UseStaticFiles();该图像在浏览器中打开了吗?是的,但当我尝试从angular应用程序加载相同的url时,该图像不起作用