Created
May 12, 2015 12:26
-
-
Save liulixiang1988/442f07fa0ac915462634 to your computer and use it in GitHub Desktop.
Web API 返回文件, 参见http://stackoverflow.com/questions/9541351/returning-binary-file-from-controller-in-asp-net-web-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HttpResponseMessage Post(string version, string environment, string filetype) | |
{ | |
var path = @"C:\Temp\test.exe"; | |
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); | |
var stream = new FileStream(path, FileMode.Open); | |
result.Content = new StreamContent(stream); | |
result.Content.Headers.ContentType = | |
new MediaTypeHeaderValue("application/octet-stream"); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment