0

I am using web api http get call which returns the response as below in controller. 'pck' below is of type ExcelPackage.

{
Byte[] fileBytes = pck.GetAsByteArray();

var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

var fileStream = new MemoryStream(fileBytes);

response.Content = new StreamContent(fileStream);

response.Content = new ByteArrayContent(fileBytes);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = DataTable.TableName + '_' + dt + ".xlsx";
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/ms-excel");
response.Content.Headers.ContentLength = fileStream.Length;
response.StatusCode = System.Net.HttpStatusCode.OK;
return response;

}

Now, in angularjs I want to download this response as excel file. How can I do the same?

I don't want to use any other jquery. So, and also dont want to use window.location.href. As, I am authorizing this method, I want to stick to http get call only.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
ghetal
  • 403
  • 2
  • 11
  • 30
  • This problem was discussed previously: http://stackoverflow.com/questions/14215049/how-to-download-file-using-angularjs-and-calling-mvc-api – Robert Sandu Mar 03 '17 at 08:45
  • Possible duplicate of [Download large size files with angular file saver](http://stackoverflow.com/questions/42543448/download-large-size-files-with-angular-file-saver) – georgeawg Mar 03 '17 at 09:11
  • You can use FileSaver.js library – Gavishiddappa Gadagi Mar 03 '17 at 10:25
  • yes.. I am now using FileSaver,js and blob object gets downloaded.. but in safari it is not working... I have lines ... `var blob = new Blob([data], { type: contentType }); saveAs(blob, filename);` – ghetal Mar 03 '17 at 14:27

0 Answers0