angular http get, download file from spring mvc server

后端 未结 1 1861
温柔的废话
温柔的废话 2021-01-21 08:57

I\'m using apache commons IOUtils copy method to send file from server to angularjs. This is my controller :

    @RequestMapping(value=\"/download\", method =          


        
1条回答
  •  孤独总比滥情好
    2021-01-21 09:41

    I had to add responseType to HTTP get request :

    $http({
    
            method: 'GET',
            url: '.../download',
            responseType: 'arraybuffer'
        })
    
        .success(function(data, status){
    
            console.log(data);
            var blob = new Blob([data], {type: 'image/jpg'});
            saveAs(blob, 'test.jpg');
        })
    
        .error(function(data, status){
            ....
        })
    

    Now it is working.

    0 讨论(0)
提交回复
热议问题