简体   繁体   中英

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/

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

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.

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:

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.

How can update a model with images attach?

How to Upload File from Angular to ASP.NET Core Web API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM