Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created July 10, 2019 19:09
Show Gist options
  • Select an option

  • Save andrIvash/1e9f8118d46045c52fe2d0fadc44d024 to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/1e9f8118d46045c52fe2d0fadc44d024 to your computer and use it in GitHub Desktop.
save pdf with axios
axios(`${apiURL}/pdf`, {
method: 'GET',
responseType: 'blob' //Force to receive data in a Blob Format
})
.then(response => {
//Create a Blob from the PDF Stream
const file = new Blob(
[response.data],
{type: 'application/pdf'});
//Build a URL from the file
const fileURL = URL.createObjectURL(file);
//Open the URL on new Window
window.open(fileURL);
})
.catch(error => {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment