1
I am using Axios to perform my application requests, and in one of the GET requests it returns a PDF file. When I do the GET request by Postman it opens a window to choose where to save the file, but when I do the request by 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’ve already looked at the official documentation on Github and it doesn’t explain how to download using Axios.
After having configured the URL he opened the PDF when the request was made, but opened another PDF, not the same that is returning when I request with Postman, I will put here my server code:
app.get('/baixarpdf', function (req, res) {

 let file = fs.createReadStream('C:/TestePDF/pdfs/teste2.pdf');
 let stat = fs.statSync('C:/TestePDF/pdfs/teste2.pdf');
 res.setHeader('Content-Length', stat.size);
 res.setHeader('Content-Type', 'application/pdf');
 res.setHeader('Content-Disposition', 'attachment; filename=teste2.pdf');
 file.pipe(res);
})
– LeonardoEbert
It was a bit unnatural, with each res declared and each Let is a line break. I really appreciate your help Bruno
– LeonardoEbert
@Leonardoebert, this code you posted in the comment is Node.js correct? Continue opening the same file?
– Bruno Rigolon
The code above is Node, when I do the request by Postman opens the correct file that is in a folder and that I specified the path, when I do the request by my client it opens a PDF that he creates on time, with a random name like: e792586d-ffc2-49eb-8d0b-66e75b7effda, and that "name" always changes
– LeonardoEbert
I even took a look and compared the requests of Postman and my client and saw that in Postman is configured "contenttype: 'application/pdf', while in my client is configured 'application/json, text/Plain, /'. I am using Axios and I am not able to configure my client’s header to 'application/pdf'
– LeonardoEbert