简体   繁体   English

将文件从 angular 11 形式传递到 asp.net 核心 5 web Z8A5DA552ED12654E72Z3 的最佳方式是什么

[英]What is the best way pass file from angular 11 form to asp.net core 5 web api

I don't want to read key line by line.我不想逐行阅读关键。 Have any good idea?有什么好主意吗?

Code: https://pastebin.ubuntu.com/p/cDTkc6GScY/代码: https://pastebin.ubuntu.com/p/cDTkc6GScY/

What is the best way pass file from angular 11 form to asp.net core 5 web api将文件从 angular 11 形式传递到 asp.net 核心 5 web Z8A5DA552ED12654E72Z3 的最佳方式是什么

To achieving the requirement of posting file from angular frontend to asp.net core web api backend, you can try to create and populate a FormData object with selected file(s), then then inject the HttpClient service and use it to make request(s). To achieving the requirement of posting file from angular frontend to asp.net core web api backend, you can try to create and populate a FormData object with selected file(s), then then inject the HttpClient service and use it to make request(s).

In your asp.net core web api backend, you may need to apply [FromForm] attribute to your action parameter, which would help specify that a parameter or property should be bound using posted form fields.在您的 asp.net 核心 web api 后端中,您可能需要将[FromForm]属性应用于您的操作绑定参数,这将有助于指定参数或属性应该是应为的表单字段。

And you may need to configure and enable CORS in your backend to set the allowed origins and HTTP methods etc. For more information, please check the following doc:您可能需要在后端配置和启用 CORS 以设置允许的来源和 HTTP 方法等。有关更多信息,请查看以下文档:

https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0 https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0

Besides, you can refer to the following SO threads to achieve the requirement.此外,您可以参考以下SO线程来实现需求。

How can update a model with images attach? 如何使用附加图像更新 model?

How to Upload File from Angular to ASP.NET Core Web API 如何将文件从 Angular 上传到 ASP.NET 内核 Web ZDB974238714CA8DE634A7CE1D083A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ASP.NET Core 2 Web Api中设置路由的最佳方法 - Best way to setup Routes in ASP.NET Core 2 Web Api 将数据从ASP.NET传递到AngularJS的最佳方法是什么? - What is the best way to pass data from ASP.NET to AngularJS? 在Web表单ASP.NET之间传递值的最佳方法 - Best way to pass values between web forms ASP.NET 在 asp.net core 中生成报告的最佳方式是什么? - What is the best way to produce the report in asp.net core? 从ASP.Net Web应用程序中的WCF验证Web用户的最佳方法是什么? - What is the best way to authenticate web users from WCF coming from ASP.Net web application? 将文件从 ASP.NET Core web api 发布到另一个 ASP.NET Core web api - Post files from ASP.NET Core web api to another ASP.NET Core web api 在Asp.net Web API项目中用于演示的最佳数据存储方式是什么 - What is the best way to use in memory data in Asp.net Web API project for demo 如果使用ASP.net WEB API,使Angularjs应用程序成为多语言的最佳方法是什么? - What is the best way to make Angularjs application as multilingual if using ASP.net WEB api? 从ASP.NET应用程序直接访问Web目录中文件的最佳方法是什么? - What's the best way to get direct file access to files within the web directories from an ASP.NET application? 角色发布到ASP.NET Core Web API返回失败 - Angular Posting to ASP.NET Core Web API returning failure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM