Response(xls file) of a POST Rest is corrupted using fileSaver.js 's saveAs method(Javascript)

Below is the detail of JAVA rest service which downloads a file from server: Method prototype:

@POST@Path("/prop/export")@Produces(MediaType.APPLICATION\_OCTET\_STREAM)@Consumes(MediaType.APPLICATION\_JSON)publicResponse exportItemsToFile(Map\<String,String\> params);

The Response is build from byte array in its implementation:

Response.ok(someByteArray)

I am using FileSaver.saveAs to download the response in a xls file using below code

var requestUri ='/wtk/rc/v1/pfm/prop/export'; var payload={"context":addCtx,"language":addLang,"country":addCountry,"swimlane":addSL}; $http.post(requestUri, payload,{ headers:{'Content-Type':'application/json'}, responseType:'arraybuffer',}).success(function (data){ var blob =newBlob([data],{type :'application/vnd.ms-excel'}); var fileName = addLang+"\_"+addCountry+".xls"; filesaver.saveAs(blob,fileName);}).error(function (){//download failed});

The response which is xls file is corrupt using the above code. **

It is because the promise returned by $http.post have blank response in case of if rest client produces octet-stream

**

But if I use some rest client like Postman, and select “Send and Download” option and save the response as xls. It is coming up fine.

Any help in this will be appreciated.

Hi,

I have axactelly the same issue. Did you get it working ?

Any help will be appreciate.

Regards,

Malik