{"id":2787,"date":"2019-10-31T15:51:55","date_gmt":"2019-10-31T14:51:55","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=2787"},"modified":"2022-07-25T08:33:25","modified_gmt":"2022-07-25T07:33:25","slug":"c-webapi-stream-file-download","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-webapi-stream-file-download\/","title":{"rendered":"C# WebApi stream file download"},"content":{"rendered":"\n<p>Source: <a href=\"https:\/\/stackoverflow.com\/a\/58575254\">https:\/\/stackoverflow.com\/a\/58575254<\/a><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    [HttpGet(\"get-file-stream\/{id}\"]\n    public async Task&lt;FileStreamResult> DownloadAsync(string id)\n    {\n        var fileName=\"myfileName.txt\";\n        var mimeType=\"application\/....\"; \n        var stream = await GetFileStreamById(id);\n\n        return new FileStreamResult(stream, mimeType)\n        {\n            FileDownloadName = fileName\n        };\n    }\n\n    [HttpGet(\"get-file-content\/{id}\"]\n    public async Task&lt;FileContentResult> DownloadAsync(string id)\n    {\n        var fileName=\"myfileName.txt\";\n        var mimeType=\"application\/....\"; \n        var fileBytes = await GetFileBytesById(id);\n\n        return new FileContentResult(fileBytes, mimeType)\n        {\n            FileDownloadName = fileName\n        };\n    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/stackoverflow.com\/a\/58575254<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-2787","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=2787"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2787\/revisions"}],"predecessor-version":[{"id":2788,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2787\/revisions\/2788"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=2787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=2787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=2787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}