I want to serve a file using MVC Web Api. Here is my controller
public HttpResponseMessage GetSupplierExcel(string supplierName)
{
var filePath = GetFileName(supplierName);
var stream = new FileStream(filePath, FileMode.Open);
var result = new HttpResponseMessage();
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType =
new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentLength = stream.Length;
result.Content.Headers.ContentDisposition.FileName = fileName;
return result;
}
Response from this action is
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Content-Type: application/octet-stream Content-Disposition: attachment; filename=abc.xlsx Content-Length: 7934 }
And there is no file being downloaded.
I'm also unable to download stream from my client using HttpClient. There is no stream, just the response string.