Skip to content

Commit

Permalink
Support Byte Range Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis committed Sep 6, 2019
1 parent 90ba45c commit 990ead7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,26 @@ S3Adapter.prototype.getFileLocation = function(config, filename) {
return (config.mount + '/files/' + config.applicationId + '/' + filename);
}

S3Adapter.prototype.getFileStream = async function(filename, req, res) {
const params = {
Key: this._bucketPrefix + filename,
Range: req.get('Range'),
};
await this.createBucket();
this._s3Client.getObject(params, (error, data) => {
if (error !== null || (data && !data.Body)) {
return res.sendStatus(404);
}
res.writeHead(206, {
'Accept-Ranges': data.AcceptRanges,
'Content-Length': data.ContentLength,
'Content-Range': data.ContentRange,
'Content-Type': data.ContentType,
});
res.write(data.Body);
res.end();
});
}

module.exports = S3Adapter;
module.exports.default = S3Adapter;

0 comments on commit 990ead7

Please sign in to comment.