Import the QingStor and initialize service with a config, and you are ready to use the initialized service. Service only contains one API, and it is "listBuckets". To use bucket related APIs, you need to initialize a bucket from service using "Bucket" function.
import { Config, QingStor } from 'qingstor-sdk';
Initialize the QingStor service with a configuration
let config = new Config('ACCESS_KEY_ID_EXAMPLE', 'SECRET_ACCESS_KEY_EXAMPLE');
var service = new QingStor(config);
List buckets
service.listBuckets({
'location': 'pek3a'
}, function(err, res) {
console.log(res.statusCode)
console.log(res.buckets);
});
Initialize a QingStor bucket
bucket = service.Bucket('test-bucket', 'pek3a');
List objects in the bucket
bucket.listObjects(function(err, res) {
console.log(res.statusCode);
console.log(res.keys);
});
Set ACL of the bucket
bucket.putACL({
'acl': [{
'grantee': {
'type': 'user',
'id': <user-id>
},
'permission': 'FULL_CONTROL'
}, {
'grantee': {
'type': 'group',
'name': <group-name>
},
'permission': 'READ'
}]
}, function(err, res) {
console.log(res.statusCode);
});
Put object
bucket.putObject('object', {
'body': fs.createReadStream('/tmp/sdk_bin')
}, function(err, res) {
console.log(res.statusCode);
});
Delete object
bucket.deleteObject('object', function(err, res) {
console.log(res.statusCode);
});
Initialize Multipart Upload
bucket.initiateMultipartUpload('object_multipart',
function(err, res) {
init_output = res;
}
);
Upload Multipart
bucket.uploadMultipart('object_multipart', {
'upload_id': init_output.upload_id,
'part_number': '0',
'body': fs.createReadStream('/tmp/sdk_bin_part_0')
}, function(err, res) {
console.log(res.statusCode);
});
bucket.uploadMultipart('object_multipart', {
'upload_id': init_output.upload_id,
'part_number': '1',
'body': fs.createReadStream('/tmp/sdk_bin_part_1')
}, function(err, res) {
console.log(res.statusCode);
});
bucket.uploadMultipart('object_multipart', {
'upload_id': init_output.upload_id,
'part_number': '2',
'body': fs.createReadStream('/tmp/sdk_bin_part_2')
}, function(err, res) {
console.log(res.statusCode);
});
Complete Multipart Upload
bucket.listMultipart('object_multipart', {
'upload_id': init_output['upload_id']
}, function(err, res) {
list_output = res;
});
bucket.completeMultipartUpload('object_multipart', {
'upload_id': init_output.upload_id,
'etag': '"4072783b8efb99a9e5817067d68f61c6"',
'object_parts': list_output.object_parts
}, function(err, res) {
console.log(res.statusCode);
});
Abort Multipart Upload
bucket.abortMultipartUpload('object_multipart', {
'upload_id': init_output.upload_id
}, function(err, res) {
console.log(res.statusCode);
});