Stream file without loading to memory in /download-user-file (#172)

This commit is contained in:
Jakub Kuczys
2023-03-28 22:05:31 +02:00
committed by GitHub
parent 7713848067
commit 9b2d74c3ad
3 changed files with 8 additions and 11 deletions

View File

@@ -313,17 +313,8 @@ app.get('/download-user-file', async (req, res) => {
return;
}
let buffer;
try {
buffer = await fs.readFile(getPathForUserFile(fileId));
} catch (e) {
console.log(`Error: file does not exist: ${getPathForUserFile(fileId)}`);
res.status(500).send('File does not exist on server');
return;
}
res.setHeader('Content-Disposition', `attachment;filename=${fileId}`);
res.send(buffer);
res.sendFile(getPathForUserFile(fileId));
});
app.post('/update-user-filename', (req, res) => {

View File

@@ -50,7 +50,7 @@ describe('/download-user-file', () => {
.set('x-actual-token', 'valid-token')
.set('x-actual-file-id', 'missing-fs-file');
expect(res.statusCode).toEqual(500);
expect(res.statusCode).toEqual(404);
});
it('returns an attachment file', async () => {

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [Jackenmen]
---
Changed budget file download endpoint to use less memory by using streams