| 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 | 12x 2x 12x 4x | import AWS from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
export default class Storage {
constructor({ region, bucket }) {
this.S3 = new AWS.S3({
region,
params: {
Bucket: bucket,
},
});
}
async put(key, data, encoding) {
return this.S3.putObject({
Key: key,
Body: encoding === 'base64' ? new Buffer(data, 'base64') : data,
}).promise();
}
async get(key) {
const meta = await this.S3.getObject({
Key: key,
}).promise();
return meta.Body;
}
}
|