Prompt Title: S3 XLSX Download with UUID

Created 1 year ago
Votes 0
Views 315 times
IT
0

Prompt Detail:

If you add .xlsx to the key when trying to retrieve the file from S3, you will get an error indicating that the key does not exist. This is because the key in S3 does not include the file extension.

To fix this, you can remove the .xlsx from the key parameter when calling the getObject method. Here's an updated code snippet:

javascript
const AWS = require('aws-sdk'); const s3 = new AWS.S3(); fastify.get('/download/:uuid', async (req, res) => { const uuid = req.params.uuid; const params = { Bucket: 'your-bucket-name', Key: `${uuid}` }; try { const data = await s3.getObject(params).promise(); res.header('Content-Disposition', `attachment; filename=your-chosen-name.xlsx`); res.header('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); res.send(data.Body); } catch (error) { console.error(error); res.send(error); } });

In this updated code, the key parameter passed to getObject method no longer includes the .xlsx extension.

avatar
Himanshu Sah
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts

0
0
node-gradle
1 year ago 2023-03-15 10:01:35 thomas
0
0
Securing Ethereum Node.
1 year ago 2023-04-12 09:30:57 Rohan
0
0
NodeJS CFM Scanner.
1 year ago 2023-04-17 17:45:05 Chetan
0
0
DevOps
1 year ago 2023-04-19 14:02:57 ak
0
0
Node.js API шаблон.
1 year ago 2023-04-25 11:48:04 John Doe
0
0
Node.js vs Deno
1 year ago 2023-08-09 18:10:35 andrew
0
0
PDF Payslip Extraction
1 year ago 2023-09-02 13:41:25 Eli Maor
0
0
Downloading files
1 year ago 2023-09-20 13:17:49 Diamondra