After receiving a PDF from a third party, I stored the file on S3. Upon checking the file on S3, I was able to view the PDF without any issues. However, when sending the PDF to the client and verifying it using Postman, an empty PDF is displayed.
Below is the code snippet:
public async getReportFromThirdParty(token) {
const params = {
headers: { Authorization: `Bearer ${token}`},
responseType: "arraybuffer",
}
let report = {};
report = await axios.get(`https://api.thirdparty.com/api/get-pdf`, params);
return report.data;
}
app.post("/download", async (req, res) => {
const token = 'abcde-secret-token';
const pdf = await getReportFromThirdParty(token);
await saveToS3(pdf) // <---- I checked and it saves the file properly on S3 as PDF
res.contentType("application/pdf");
return res.status(200).send(pdf); // <--- this returns an empty pdf file
});
Could you offer any insights?