Relative Content

Tag Archive for node.jsexpressaws-lambdadownloadaws-s3-client

This API controller is working fine locally but when the server is deployed as lambda function the downloaded zipfile is corrupt

export const downloadFiles3 = async (req: Request, res: Response) => { const key = req.params.key; try { const getObjectParams = { Bucket: process.env.AWS_BUCKET || ”, Key: key, }; const data = await s3.getObject(getObjectParams).promise(); res.setHeader(‘Content-Type’, ‘application/zip’); res.setHeader(‘Content-Disposition’, `attachment; filename=${key}`); res.send(data.Body); console.log(‘File sent successfully.’); } catch (error) { if (!res.headersSent) { if (error instanceof Error) { console.log(‘Error […]