Listing Buckets
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
You can call ObsClient.listBuckets to list buckets. Sample code is as follows:
// Import the OBS library.
// Use npm to install the client.
var ObsClient = require('esdk-obs-nodejs');
// Use source codes to install the client.
// var ObsClient = require('./lib/obs');
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'https://your-endpoint'
});
// List buckets.
obsClient.listBuckets({
QueryLocation : true
}, (err, result) => {
if(err){
console.error('Error-->' + err);
}else{
console.log('Status-->' + result.CommonMsg.Status);
if(result.CommonMsg.Status < 300 && result.InterfaceResult){
console.log('RequestId-->' + result.InterfaceResult.RequestId);
console.log('Owner:');
console.log('ID-->' + result.InterfaceResult.Owner.ID);
console.log('Name-->' + result.InterfaceResult.Owner.Name);
console.log('Buckets:');
for(let i=0;i<result.InterfaceResult.Buckets.length;i++){
console.log('Bucket[' + i + ']:');
console.log('BucketName-->' + result.InterfaceResult.Buckets[i].BucketName);
console.log('CreationDate-->' + result.InterfaceResult.Buckets[i].CreationDate);
console.log('Location-->' + result.InterfaceResult.Buckets[i].Location);
}
}
}
});
- Obtained bucket names are listed in the lexicographical order.
- Set QueryLocation to true and then you can query the bucket location when listing buckets.
Last Article: Creating a Bucket
Next Article: Deleting a Bucket
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.