获取存储桶所在地域

更新时间: 2020-03-24

本节介绍如何获取存储桶所在的地域。

以下代码用于获取存储桶所在的地域(称为Region或Location):

// Endpoint以华北三为例,其它Region请按实际情况填写
String endpoint = "oss.cn-north-3.inspurcloudoss.com";
String accessKey = "<yourAccessKey>";
String secretKey = "<yourSecretKey>";
String bucketName = "<yourBucketName>";

//创建OSSClient实例
OSSClientImpl ossClient = new OSSClientImpl(endpoint, accessKey, secretKey);

//获取bucket所在地域
String bucketLocation = ossClient.getBucketLocation(bucketName);
System.out.println(bucketLocation);