Using the aws-sdk module and Express 4.13, it\'s possible to proxy a file from S3 a number of ways.
This callback version will return the file body as a
Building on André Werlang's answer, we have done the following to augment AWS Request objects with a forwardToExpress method:
const _ = require('lodash');
const AWS = require('aws-sdk');
AWS.Request.prototype.forwardToExpress = function forwardToExpress(res, next) {
this
.on('httpHeaders', function (code, headers) {
if (code < 300) {
res.set(_.pick(headers, 'content-type', 'content-length', 'last-modified'));
}
})
.createReadStream()
.on('error', next)
.pipe(res);
};
Then, in our route handlers, we can do something like this:
s3.getObject({Bucket: myBucket, Key: myFile}).forwardToExpress(res, next);