Created
December 20, 2019 14:26
-
-
Save Arunmainthan/bf8ad85d00fcac2ee70e6fb2d5a34544 to your computer and use it in GitHub Desktop.
Nodejs Express Download file from s3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const request = require('request'); | |
app.get('/download-file', function (req, res) { | |
// sdk way | |
var s3 = new AWS.S3({}); | |
var options = { | |
Bucket: 'my-bucket-name', | |
Key: file, | |
}; | |
s3.getObject(options, function (err, data) { | |
res.attachment(file); | |
res.send(data.Body); | |
}); | |
// http way | |
request('https://s3-ap-southeast-2.amazonaws.com/my-bucket-name/mypdf.pdf') | |
.pipe(res.set('Content-Type', 'application/pdf').set('Content-Disposition', 'inline; filename="mypdf.pdf"')) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
express and AWS v3 S3: