Download using the axios?

0

I'm using Axios to make the requests of my application, and in one of the GET requests returns a PDF file. When I make the GET request by Postman it opens a window to choose where to save the file, but when I make the request for my application it does not download. Which method should I use to download the file?

axios.get('/server/pdfs')
.then(function (response) {
  //Qual método usar aqui para efetuar o download??
})
.catch(function (error) {
  console.log(error)
})

I have already looked at the official documentation on GitHub and it does not explain how to download using Axios.

    
asked by anonymous 04.08.2017 / 15:07

1 answer

1

Just create the file with Blog and passing the mime type. Then open a new link by passing the linked url. You can also use the link created in items of type a and iframe .

axios.get('/server/pdfs')
.then(function(response) {
    var blob = new Blob([response.data], {
          type: 'application/pdf'
    });
    var url = window.URL.createObjectURL(blob)
    window.open(url);
  })
  .catch(function(error) {
        console.log(error)
});
    
04.08.2017 / 18:45