I'm using react-pdf library and it generates me a blob and url as shown in the docs: https://react-pdf.org/advanced#on-the-fly-rendering Blob object copied from the console:
{blob: Blob}
blob: Blob
size: 3597607
type: "application/pdf"
[[Prototype]]: Blob
[[Prototype]]: Object
I try to upload this to S3. Frontend code:
const fileName = Date.now().toString() + ".pdf";
const file = new File([blob], fileName);
axios
.post("api/upload-poster", {
fileName,
file,
})
.then(({ data }) => console.log(data));
Backend code (nextjs handler):
const { fileName, file } = req.body;
const params = {
Bucket: "my-bucket-name",
Key: fileName,
Body: file,
contentType: "application/pdf",
};
const uploaded = await S3.upload(params).promise();
res.status(200).json({ uploaded });
I get the error Error: Unsupported body payload object