Serve pdf file in get route in Astro

Hi, im trying to serve a pdf file in a get route, as such:
import fs from "fs";

export async function get({ params, request }) {
const buff = fs.readFileSync("public/resume.pdf", "binary");
fs.createReadStream;
return new Response(buff.toString(), {
status: 200,
headers: {
"content-type": "application/pdf",
"content-disposition": "attachment; filename=resume.pdf",
},
});
}
import fs from "fs";

export async function get({ params, request }) {
const buff = fs.readFileSync("public/resume.pdf", "binary");
fs.createReadStream;
return new Response(buff.toString(), {
status: 200,
headers: {
"content-type": "application/pdf",
"content-disposition": "attachment; filename=resume.pdf",
},
});
}
and getting this error(see attachment) anyone know how to do this?
1 Reply
J no dox
J no doxOP16mo ago
the reason i want to do it this way instead of serving directly from /public is to have a different file name form the route
Want results from more Discord servers?
Add your server