Hi guys,
I’m creating a forge app, which collects some data and sends it to an external Node.js/express server, where it generates a pdf file out of that data. This pdf file is sent back to my forge app, but I’m not able to recieve it as a file. Instead I get my typical APIResponse object, which wouldn’t be a problem, if I could puzzle my pdf together out of the arrayBuffer. But if I try to send the buffer to my frontend to build the file, only an empty json object comes in. I don’t know why, maybe to buffer is too big? Then I tried a little workaround to write the buffer into a String, but this takes longer than 10 seconds and the request stops with a timeout. Could anyone please tell me what I’m doing wrong, or better how to send pdf files right?
Here are some code snippets.
The Node.js/express server
app.post('/createOffer', async (req, res)=>{
const sampleArg = req.body;
const filepath = pdf.createPdf(sampleArg);
const file = fs.readFileSync(filepath);
res.contentType("application/pdf");
return res.send(file)
});
backend in my forge app
resolver.define('exportPdf', async (req) => {
const data = req.payload;
const result = await api.fetch("https://url.net:PORT/createPdf", {
method: "POST",
headers: {
'Content-Type': 'application/pdf',
Accept: 'application/pdf'
},
body: JSON.stringify(data)
})
const ab = await result.arrayBuffer();
const uint = new Uint8Array(ab);
//this takes all the time, its 1.6million bytes to write into that String
let string = "";
uint.forEach(byte => string += byte.toString(16).padStart(2, "0") + " ")
return string;
});
Cheers and thank you a lot!