Un bucket es un contenedor para almacenar objetos en Object Storage Service (OSS). Este tema describe cómo consultar la información de un bucket.
Código de ejemplo
El siguiente código recupera información de un bucket, como su región y fecha de creación.
const OSS = require('ali-oss');
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
region: 'yourRegion',
// Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Set bucket to the name of your bucket.
bucket: 'yourBucketName',
});
async function getBucketInfo() {
// Specify the bucket name. For example, examplebucket.
const bucket = 'examplebucket'
const result = await client.getBucketInfo(bucket)
// Get the region of the bucket.
console.log(result.bucket.Location)
// Get the name of the bucket.
console.log(result.bucket.Name)
// Get the ID of the bucket owner.
console.log(result.bucket.Owner.ID)
// Get the name of the bucket owner. The name is the same as the owner ID.
console.log(result.bucket.Owner.DisplayName)
// Get the creation time of the bucket.
console.log(result.bucket.CreationDate)
// Get the storage class of the bucket.
console.log(result.bucket.StorageClass)
// Get the versioning state of the bucket.
console.log(result.bucket.Versioning)
}
getBucketInfo()
Referencias
Para consultar el código de ejemplo completo sobre cómo obtener información de un bucket, consulte Ejemplo en GitHub.
Para obtener más información sobre la operación de API para recuperar información de un bucket, consulte GetBucketInfo.