I'm trying to get an excel from the api, but eventhough I am setting it on the controller side, when it comes to the angular side, response doesn't have any content in it but headers.
This is how I'm setting the HttpResponseMessage
on the Controller side:
HttpResponseMessage httpResponseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
ExcelPackage package = new ExcelPackage();
using (package)
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("LIST of FILES");
worksheet.Cells["A1"].LoadFromCollection(files);
httpResponseMessage.Content = new ByteArrayContent(package.GetAsByteArray());
httpResponseMessage.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
httpResponseMessage.Content.Headers.ContentDisposition.FileName = "EXCEL - "+ DateTime.Now.ToString();
httpResponseMessage.Content.Headers.ContentType = new System.Net.Http.Headers
.MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
httpResponseMessage.Content.Headers.Expires = DateTime.Now.AddMinutes(5);
}
return httpResponseMessage;
And this is how I send request to api:
postWithApiUrl<T>(url: string, body: T): Promise<any> {
const headers = new HttpHeaders({
'Content-Type': 'application/json',
});
return new Promise((resolve, reject) => {
this.http.post(url, body, { headers }).subscribe(response => {
resolve(response);
});
});
}
And I use this returned promise like this;
this.postWithApiUrl(url, this.req).then(response => {
console.log(response);
});
This is how I receive the response:
Where am I making the mistake at?