Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 1
Message 1 of 2

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)
public Response 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 = new Blob([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.

 
1 Reply
Ground Controller Lvl 1
Message 2 of 2

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

Hi,

 

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

Any help will be appreciate.

 

Regards,

Malik