-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
Not sure because I haven't tested this yet, but it seems that this may get some bugs with high concurrency, because files are always being generated with the same name, please tell me if I am wrong. Maybe a way to fix this intuitive problem is to generate a random filename on creation, send to before fetching. Please tell me what do you think about this, have you tested the concurrency on this?
createAndDownloadPdf = () => {
axios.post('/create-pdf', this.state)
.then((filename) => axios.get('fetch-pdf', { responseType: 'blob', filename}))
.then((res) => {
const pdfBlob = new Blob([res.data], { type: 'application/pdf' });
saveAs(pdfBlob, 'newPdf.pdf');
})
}
app.post('/create-pdf', (req, res) => {
const rndFilename = randomfilename(); /* you can implement this as you wish maybe using a your favourite hashfuncion*/
pdf.create(pdfTemplate(req.body), {}).toFile( rndFilename , (err, rndFilename ) => {
if(err) {
res.send(Promise.reject());
}
res.send(Promise.resolve(rndFilename));
});
});
app.get('/fetch-pdf', (req, res) => {
res.sendFile(`${__dirname}/${res.filename}`)
});
sabarinathan145
Metadata
Metadata
Assignees
Labels
No labels