Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm using FileSaver.js https://github.com/alferov/angular-file-saver to download generated file by spring boot application ,I have rest service that return the file as byte array data.

@RequestMapping(value = "/generateReport/{reportId}/{parameters}",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
    @Timed
    public  byte[] generateReport(@PathVariable("reportId") String reportId,
                                @PathVariable("parameters") String parameters
                                ) {

        byte[] bFile;
        //some code

        return bFile;
     }

Angular service

'generateReport': {
            method: 'GET',
            responseType: 'arraybuffer' ,
            url: 'adap_report/api/generateReport/:reportId/:parameters',
            transformResponse: function (data) {
                if (data) {
                    data = angular.fromJson(data);
                }
                return data;
                }
        },

Angularjs controller

 vm.generateReport = function() {
        Report.generateReport({reportId:entity.id,parameters:angular.toJson(vm.parameterList)}, function(result) {
        var data = new Blob([result], { type: 'application/octet-stream' });
        FileSaver.saveAs(data, 'text.txt');
        });
    };

File saver works and file downloaded but The content is wrong ,I just get file with this content

[object Object]  

Can anyone please help me to save generated file with angular FileSaver.js library?

share|improve this question
    
1. data is probably object with some property that has content of your file. add console.log(data) before FileSaver.saveAs to check what it looks like. – sielakos 16 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.