![]() ![]() ![]() These four variants don’t differ much, you can use any of them to construct a FileResult object at your convenience. The FileResult type is an abstract type, and it has four concrete implementations: FileContentResult, FileStreamResult, VirtualFileResult, and PhysicalFileResult. But most times we still want to use the generic ActionResult because it covers many other useful return types, such as BadRequest, NoContent, and so on. When we want to return a file response, we can explicitly set the return type for the action method to be FileResult, which is a type inherited from ActionResult. In ASP.NET Core, a Web API action method usually returns an ActionResult object. The full solution can be found in my GitHub repository, which includes a web project for uploading/downloading files and an integration test project for testing controller methods. In the final HTML page, end users can left-click a hyperlink to download the file or right-click the link to choose “ Save Link As” in the context menu and save the file. ![]() In this article, I will use a demo Web API application in ASP.NET Core to show you how to transmit files through an API endpoint.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |