Paket, Object Storage Service (OSS) içinde depolanan nesneleri içeren bir kapsayıcıdır. OSS'deki tüm nesneler paketlerde bulunur. Paketler alfabetik sırayla listelenir. Belirli koşulları karşılayan ve mevcut Alibaba Cloud hesabınıza ait olan paketleri tüm bölgelerde listeleyebilirsiniz.
Kullanım notları
Bu konudaki örnek kodu çalıştırmadan önce, özel etki alanı adı veya Security Token Service (STS) gibi yöntemleri kullanarak bir OSSClient örneği oluşturmanız gerekir. Daha fazla bilgi için bkz. Başlatma (Android SDK).
Bir Alibaba Cloud hesabındaki tüm paketleri listeleme
Aşağıdaki örnek kod, mevcut Alibaba Cloud hesabınızın tüm bölgelerindeki paketlerin nasıl listeleneceğini gösterir:
// List all buckets in all regions of your account.
ListBucketsRequest request = new ListBucketsRequest();
ossClient.asyncListBuckets(request, new OSSCompletedCallback<ListBucketsRequest, ListBucketsResult>() {
@Override
public void onSuccess(ListBucketsRequest request, ListBucketsResult result) {
List<OSSBucketSummary> buckets = result.getBuckets();
for (int i = 0; i < buckets.size(); i++) {
Log.i("info", "name: " + buckets.get(i).name + " "
+ "location: " + buckets.get(i).location);
}
}
@Override
public void onFailure(ListBucketsRequest request, ClientException clientException, ServiceException serviceException) {
// The request failed.
if (clientException != null) {
// A client exception occurred, such as a network exception.
clientException.printStackTrace();
}
if (serviceException != null) {
// A server exception occurred.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
Adlarında belirtilen ön ek bulunan paketleri listeleme
Aşağıdaki örnek kod, mevcut Alibaba Cloud hesabınızın tüm bölgelerinde adlarında example ön eki bulunan paketlerin nasıl listeleneceğini gösterir:
Ön ek, bulanık eşleştirme için kullanılır. Sorgu, adları belirtilen ön ekle başlayan tüm paketleri döndürür. Örneğin, ön eki a olarak ayarlarsanız abucket ve abcbucket gibi paketler döndürülür.
// Specify the URL of the STS application server. For example, http://example.com.
String stsServer = "http://example.com";
// Use OSSAuthCredentialsProvider to automatically update the token when it expires.
OSSCredentialProvider credentialProvider = new OSSAuthCredentialsProvider(stsServer);
ClientConfiguration config = new ClientConfiguration();
OSSClient ossClient = new OSSClient(getApplicationContext(), credentialProvider, config);
ListBucketsRequest request = new ListBucketsRequest();
// List buckets with the prefix 'example' in all regions of your account.
request.setPrefix("example");
ossClient.asyncListBuckets(request, new OSSCompletedCallback<ListBucketsRequest, ListBucketsResult>() {
@Override
public void onSuccess(ListBucketsRequest request, ListBucketsResult result) {
List<OSSBucketSummary> buckets = result.getBuckets();
for (int i = 0; i < buckets.size(); i++) {
Log.i("i", "name: " + buckets.get(i).name + " "
+ "location: " + buckets.get(i).location);
}
}
@Override
public void onFailure(ListBucketsRequest request, ClientException clientException, ServiceException serviceException) {
// The request failed.
if (clientException != null) {
// A client exception occurred, such as a network exception.
clientException.printStackTrace();
}
if (serviceException != null) {
// A server exception occurred.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
İşaretçiyle belirtilen paketten sonra alfabetik olarak gelen paketleri listeleme
Aşağıdaki örnek kod, mevcut Alibaba Cloud hesabınızın tüm bölgelerinde examplebucket adlı paketten sonra alfabetik sıraya göre gelen paketlerin nasıl listeleneceğini gösterir:
Ön ek tabanlı sorgular, adları belirtilen ön ekle başlayan tüm paketleri döndürür. Örneğin, a ön ekiyle yapılan bir sorgu abucket ve abcbucket gibi paketleri döndürür.
Sorgu sonucu, bulanık eşleşme tarafından döndürülen ilk paketi ve sonraki tüm paketleri içerir.
// Specify the URL of the STS application server. For example, http://example.com.
String stsServer = "http://example.com";
// Use OSSAuthCredentialsProvider to automatically update the token when it expires.
OSSCredentialProvider credentialProvider = new OSSAuthCredentialsProvider(stsServer);
ClientConfiguration config = new ClientConfiguration();
OSSClient ossClient = new OSSClient(getApplicationContext(), credentialProvider, config);
ListBucketsRequest request = new ListBucketsRequest();
// List buckets that come after 'examplebucket' in alphabetical order in all regions of your account.
request.setMarker("examplebucket");
ossClient.asyncListBuckets(request, new OSSCompletedCallback<ListBucketsRequest, ListBucketsResult>() {
@Override
public void onSuccess(ListBucketsRequest request, ListBucketsResult result) {
List<OSSBucketSummary> buckets = result.getBuckets();
for (int i = 0; i < buckets.size(); i++) {
Log.i("i", "name: " + buckets.get(i).name + " "
+ "location: " + buckets.get(i).location);
}
}
@Override
public void onFailure(ListBucketsRequest request, ClientException clientException, ServiceException serviceException) {
// The request failed.
if (clientException != null) {
// A client exception occurred, such as a network exception.
clientException.printStackTrace();
}
if (serviceException != null) {
// A server exception occurred.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
Belirtilen sayıda paketi listeleme
Aşağıdaki örnek kod, mevcut Alibaba Cloud hesabınızın tüm bölgelerindeki paketleri listelemeyi ve listelenebilecek maksimum paket sayısını 500 olarak ayarlamayı gösterir:
// Specify the URL of the STS application server. For example, http://example.com.
String stsServer = "http://example.com";
// Use OSSAuthCredentialsProvider to automatically update the token when it expires.
OSSCredentialProvider credentialProvider = new OSSAuthCredentialsProvider(stsServer);
ClientConfiguration config = new ClientConfiguration();
OSSClient ossClient = new OSSClient(getApplicationContext(), credentialProvider, config);
ListBucketsRequest request = new ListBucketsRequest();
// List buckets in all regions of your account and limit the number of buckets returned to 500. The default value is 100. The maximum value is 1000.
request.setMaxKeys(500);
ossClient.asyncListBuckets(request, new OSSCompletedCallback<ListBucketsRequest, ListBucketsResult>() {
@Override
public void onSuccess(ListBucketsRequest request, ListBucketsResult result) {
List<OSSBucketSummary> buckets = result.getBuckets();
for (int i = 0; i < buckets.size(); i++) {
Log.i("i", "name: " + buckets.get(i).name + " "
+ "location: " + buckets.get(i).location);
}
}
@Override
public void onFailure(ListBucketsRequest request, ClientException clientException, ServiceException serviceException) {
// The request failed.
if (clientException != null) {
// A client exception occurred, such as a network exception.
clientException.printStackTrace();
}
if (serviceException != null) {
// A server exception occurred.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
İlgili Konular
Tam örnek kod için bkz. GitHub örneği.
Bu işlem için API referansı hakkında bilgi edinmek için bkz. ListBuckets (GetService).