Created
July 10, 2019 19:09
-
-
Save andrIvash/1e9f8118d46045c52fe2d0fadc44d024 to your computer and use it in GitHub Desktop.
save pdf with axios
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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