When I initiate a get
request in angular against a webapi
controller that responds with a file wrapped in an HttpResponseMessage
the browser doesn't recognize that it's a file download and the data is lost.
I checked in fiddler and I can see that the binary data is present in the response.
I'm initiating the get request with this:
return $http.get(serviceURLRoot + 'api/myreport/' + dateParams.StartDate + '/' + dateParams.EndDate, { withCredentials: true }).success(function (data) {
});
If I type the request directly into the address bar I get the file back just fine. Using window.open
also works:
window.open(serviceURLRoot + 'api/rawdatareport/' + dateParams.StartDate + '/' + dateParams.EndDate);
Why doesn't $http.get
work?
EDIT -----
Here's the HttpResponseMessage as built on the server:
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(pck.GetAsByteArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {
FileName = "myReport.xlsx"
};
return result;