[英]Backend gets a pdf from a third-party. How can I send it via REST api to my client?
I get a pdf from a third party.我从第三方那里得到一个 pdf。 I save the file on S3.我将文件保存在 S3 上。 I can see the file on S3 and when I open it I can see my PDF. However, when I passed the pdf to the client and check it on Postman I get an empty PDF.我可以在 S3 上看到该文件,当我打开它时,我可以看到我的 PDF。但是,当我将 pdf 传递给客户端并在 Postman 上检查它时,我得到一个空的 PDF。
Here is my code:这是我的代码:
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
});
Any ideas?有任何想法吗?
im going to guess your app is an node express app
so therefore you likely need to我猜你的应用程序是一个node express app
,因此你可能需要
res.sendFile();
More info found on the express site在快递网站上找到更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.