View of File List
Last Updated:2020-10-23
Basic Introduction
When bucket is created, you can view the bucket list owned and acquire the object information list of the specified bucket from BOS. BOS supports the use of API and SDK to list bucket and object.
Operation Method
- Use API to list buckets. ListBucket Interface lists all buckets
-
List buckets through SDK
- Use API to list objects Use Listobjects API Interface to list objects
-
Use SDK to acquire object list
Example
Code samples of bucket list acquired with the use of Java SDK are as follows.
//Baidu Cloud master user AccessKey has all the API access permissions with high risk. You are highly recommended to create sub-users for API access or routine maintenance.
String ACCESS_KEY_ID="<yourAccessKeyId>";
String SECRET_ACCESS_KEY= "<yourAccessKeySecret>";
String ENDPOINT="bj.bcebos.com";
//Create BOS examples
BosClientConfiguration config=new BosClientConfiguration();
config.setCredentials(new DefaultBceCredentials(ACCESS_KEY_ID,SECRET_ACCESS_KEY));
config.setEndpoint(ENDPOINT);
BosClient bosClient=new BosClient(config);
// Get the user's bucket list
ListBucketsResponse listing = bosClient.listBuckets();
// Traverse all buckets
for (BucketSummary bucketSummary : listing.getBuckets()) {
System.out.println("Bucket: " + bucketSummary.getName());
}
Code samples of object list in the specified bucket acquired with the use of Java SDK are as follows.
// Acquire the object list of the bucket specified by users.
ListObjectsResponse listing = bosClient.listObjects(BUCKET_NAME);
// Traverse all objects
for (BosObjectSummary objectSummary : listing.getContents()) {
System.out.println("ObjectKey: " + objectSummary.getKey());
}