Last active
December 26, 2015 15:38
-
-
Save shiranGinige/7173740 to your computer and use it in GitHub Desktop.
I just want to save a file temporarily and return it as a stream for a HTTP response. Azure don't like me writing things to the file system? Here's how to get around.
This file contains hidden or 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
var data = getData(); | |
var stringBuilder = new StringBuilder(); | |
stringBuilder.AppendLine("Header"); | |
foreach (var item in data) | |
{ | |
stringBuilder.AppendLine(data.Stuff) | |
} | |
var response = new HttpResponseMessage(HttpStatusCode.OK); | |
response.Content = new StreamContent(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(stringBuilder.ToString()))); | |
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); | |
response.Content.Headers.ContentDisposition.FileName = "FileName"; | |
return response; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment