Download a PDF received from an API with AngularJS

2

I have an API that returns me a PDF file.

I want to make angular hitting this route and forcing the download of the PDF file.

Today I do this:

var blob = new Blob([arquivo], {type: "application/pdf"});
saveAs(blob, 'arquivo.pdf');

The download works, but the pdf file is blank. If I hit the route manually, the file comes complete.

    
asked by anonymous 15.02.2017 / 14:25

1 answer

3

The responseType is missing from the request.

The problem was not at this point, but in the request call, where the GET was done, the responseType was missing.

The working code looks like this:

$http.get('/api/download/' + uid, {responseType:'arraybuffer'});
    
15.02.2017 / 14:34