-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.s3.js
41 lines (40 loc) · 1.13 KB
/
storage.s3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = function(bucketInfo){
var aws = require('aws-sdk');
aws.config.update({
"region": 'us-east-1'
});
aws.config.update(bucketInfo['storage_config']);
var s3 = new aws.S3();
this.read = function(path, callback){
s3.client.getObject({
Bucket: bucketInfo['storage_config']['bucket'],
Key: path
}).on('complete', function(response){
var error = null;
if (!response || response.error || !response.data){
error = response.error && response.error.message || 'unknwon s3 error';
}
console.info('s3 read done. error: ' + error);
if (callback) {
callback(error, response && response.data && response.data.Body);
}
}).send();
};
this.write = function(path, data, callback){
s3.client.putObject({
Bucket: bucketInfo['storage_config']['bucket'],
Key: path,
Body: data
}).on('complete', function(response){
var error = null;
if (!response || response.error || !response.data){
error = response.error && response.error.message || 'unknwon s3 error';
}
console.log('s3 write done: error: ' + error);
if (callback) {
callback(error);
}
}).send();
};
return this;
}