Skip to content

Instantly share code, notes, and snippets.

@dannycoates
Last active June 7, 2017 06:53
Show Gist options
  • Save dannycoates/f75e37df25968ff74475156b894669d4 to your computer and use it in GitHub Desktop.
Save dannycoates/f75e37df25968ff74475156b894669d4 to your computer and use it in GitHub Desktop.
const conf = require('./config.js');
const fs = require('fs');
const AWS = require('aws-sdk');
if (conf.s3_bucket) {
const bucket = new AWS.S3({ params: { Bucket: conf.s3_bucket } });
module.exports = {
length: function(id) {
return bucket.headObject({ Key: id }).promise();
},
get: function(id) {
return bucket.getObject({ Key: id }).createReadStream();
},
set: function(id, stream) {
return bucket.upload({ Key: id, Body: stream }).promise();
},
del: function(id) {
return bucket.deleteObject({ Key: id }).promise();
}
};
} else {
module.exports = {
length: function(id) {},
get: function(id) {},
set: function(id, stream) {},
del: function(id) {}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment