simple-storage-service
Version:
s3 client
39 lines (38 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var client_s3_1 = require("@aws-sdk/client-s3");
var SimpleStorageService = (function () {
function SimpleStorageService(s3Client, config) {
this.s3Client = s3Client;
this.config = config;
this.upload = this.upload.bind(this);
this.delete = this.delete.bind(this);
}
SimpleStorageService.prototype.upload = function (directory, name, data) {
var key = name;
if (directory && directory.length > 0) {
key = directory + '/' + name;
}
var i = {
Bucket: this.config.bucket,
Key: key,
Body: data
};
var p = new client_s3_1.PutObjectCommand(i);
return this.s3Client.send(p).then(function (r) { return JSON.stringify(r); });
};
SimpleStorageService.prototype.delete = function (directory, name) {
var key = name;
if (directory && directory.length > 0) {
key = directory + '/' + name;
}
var i = {
Bucket: this.config.bucket,
Key: key
};
var p = new client_s3_1.DeleteObjectCommand(i);
return this.s3Client.send(p).then(function (r) { return true; });
};
return SimpleStorageService;
}());
exports.SimpleStorageService = SimpleStorageService;