Created
December 4, 2015 14:01
-
-
Save belchev/6f3d200eed8bbbed9306 to your computer and use it in GitHub Desktop.
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
public class FileResult : IHttpActionResult | |
{ | |
private readonly byte[] _fileBinary; | |
private readonly string _contentType; | |
private string _fileName; | |
public FileResult(byte[] fileBinary, string contentType, string fileName) | |
{ | |
this._fileBinary = fileBinary; | |
this._contentType = contentType; | |
this._fileName = fileName; | |
} | |
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken) | |
{ | |
var response = new HttpResponseMessage(HttpStatusCode.OK); | |
//var response = new HttpResponseMessage(HttpStatusCode.OK) | |
//{ | |
// Content = new StreamContent(File.OpenRead(@"C:\www\templates\test.zip")) | |
//}; | |
response.Content = new ByteArrayContent(this._fileBinary); | |
response.Content.Headers.ContentType = new MediaTypeHeaderValue(this._contentType); | |
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); | |
response.Content.Headers.ContentDisposition.FileName = this._fileName; | |
return Task.FromResult(response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment