I am reading a solution how to download a file from asp.net api here: https://stackoverflow.com/a/3605510/1881147
therefore I create an API handler as the following code:
public HttpResponseMessage Post([FromBody]dynamic result)
{
var localFilePath = graphDataService.SaveToExcel(graphVm, graphImgUrl);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "testing.xlsx";
response.Content.Headers.ContentType = new MediaTypeHeaderValue("MS-Excel/xls");
return response;
//return graphDataService.SaveToExcel(graphVm, graphImgUrl);
}
This is my client side:
$http({
url: '/msexcel',
method: 'post',
params: { param: JSON.stringify(param) }
}).success(function (data, status, headers, config) {
console.log(data); //HOW DO YOU HANDLE the response here so it downloads?
}).error(function (data, status, headers, config) {
console.log(status);
});
How do you do you handle the success so it downloads the file as an .xls file? thx