百度智能云

All Product Document

          Object Storage

          View of File List

          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

          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());
                  }
          Previous
          Data Copy
          Next
          Select Object