I am trying to display pdf files from MongoDB using Multer. I am rendering the pdf in my react app.
When I run it locally (express app), it is working perfectly fine. However when I use the AWS Lambda hosted API link, it only displays the name of PDF, and renders a blank PDF:
Do I need to install any other dependency for AWS Lambda?
I dont want to use S3, or any other AWS storage.
This is my resume Schema
const resumeSchema = new mongoose.Schema({
name: String,
data: Buffer,
contentType: String,
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
});
This is the response I am sending after finding the document:
res.setHeader("Content-Type", matchedResume.contentType);
res.setHeader(
"Content-Disposition",
`inline; filename="${matchedResume.name}"`
);
res.status(200).send(matchedResume.data);
This is how I am rendering the pdf in react app:
onClick={() => {
const config = {
method: "get",
headers: {
Authorization: `Bearer ${token}`,
},
url: `http://localhost:8257/user/resume/resumes?rId=${props.resume.rId}`,
responseType: "blob",
};
axios(config)
.then((res) => {
const blobUrl = window.URL.createObjectURL(
new Blob([res.data], { type: "application/pdf" })
);
// Open the blob URL in a new tab
window.open(blobUrl, "_blank");
})
.catch((error) => console.log(error));
}}
Syed Faraz Hasan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.