cos:GetBucket. For more information on authorization, see CAM-supported business APIs.cos:GetBucketObjectVersions. For more information on authorization, see CAM-supported business APIs.Feature Name | Description | Example code |
List objects. | Provides the capability to query some or all objects in a bucket. | |
List object versions. | Provides the capability to query some or all objects and their historical versions in a bucket. |
String bucketName = "examplebucket-1250000000"; // Format: BucketName-APPID;final GetBucketRequest getBucketRequest = new GetBucketRequest(bucketName);// Prefix matching, used to specify the prefix address of the returned objects.getBucketRequest.setPrefix("dir/");// The maximum number of entries returned in a single response, with a default value of 1,000.getBucketRequest.setMaxKeys(100);cosXmlService.getBucketAsync(getBucketRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketResult getBucketResult = (GetBucketResult) result;if (getBucketResult.listBucket.isTruncated) {// Indicates that data is truncated and the next page of data needs to be fetched.prevPageResult = getBucketResult;}}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String bucketName = "examplebucket-1250000000"; // Format: BucketName-APPID;GetBucketRequest getBucketRequest = new GetBucketRequest(bucketName);// Prefix matching, used to specify the prefix address of the returned objects.getBucketRequest.setPrefix("dir/");// prevPageResult is the result returned from the previous page, and the nextMarker here indicates the starting position of the next page.String nextMarker = prevPageResult.listBucket.nextMarker;getBucketRequest.setMarker(nextMarker);// The maximum number of entries returned in a single response, with a default value of 1,000.getBucketRequest.setMaxKeys(100);cosXmlService.getBucketAsync(getBucketRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketResult getBucketResult = (GetBucketResult) result;if (getBucketResult.listBucket.isTruncated) {// Indicates that data is truncated and the next page of data needs to be fetched.}}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String bucketName = "examplebucket-1250000000"; // Format: BucketName-APPID;GetBucketRequest getBucketRequest = new GetBucketRequest(bucketName);// Prefix matching, used to specify the prefix address of the returned objects.getBucketRequest.setPrefix("dir/");// The maximum number of entries returned in a single response, with a default value of 1,000.getBucketRequest.setMaxKeys(100);// The delimiter is a single character. If a Prefix is present,// Then, identical paths between the Prefix and the delimiter are grouped into a single category and defined as the Common Prefix.// Then, all Common Prefixes are listed. If no Prefix is present, the process starts from the beginning of the path.getBucketRequest.setDelimiter("/");cosXmlService.getBucketAsync(getBucketRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketResult getBucketResult = (GetBucketResult) result;}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String bucketName = "examplebucket-1250000000"; // Format: BucketName-APPID;final GetBucketObjectVersionsRequest getBucketRequest =new GetBucketObjectVersionsRequest(bucketName);// Prefix matching, used to specify the prefix address of the returned objects.getBucketRequest.setPrefix("dir/");// The maximum number of entries returned in a single response, with a default value of 1,000.getBucketRequest.setMaxKeys(100);cosXmlService.getBucketObjectVersionsAsync(getBucketRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketObjectVersionsResult getBucketResult =(GetBucketObjectVersionsResult) result;if (getBucketResult.listVersionResult.isTruncated) {// Indicates that data is truncated and the next page of data needs to be fetched.prevPageResult = getBucketResult;}}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
String bucketName = "examplebucket-1250000000"; // Format: BucketName-APPID;final GetBucketObjectVersionsRequest getBucketRequest =new GetBucketObjectVersionsRequest(bucketName);// Prefix matching, used to specify the prefix address of the returned objects.getBucketRequest.setPrefix("dir/");// The maximum number of entries returned in a single response, with a default value of 1,000.getBucketRequest.setMaxKeys(100);// prevPageResult is the result returned from the previous page, and the nextMarker and nextVersionIdMarker here// Indicates the starting position of the next page.getBucketRequest.setKeyMarker(prevPageResult.listVersionResult.nextKeyMarker);getBucketRequest.setVersionIdMarker(prevPageResult.listVersionResult.nextVersionIdMarker);cosXmlService.getBucketObjectVersionsAsync(getBucketRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketObjectVersionsResult getBucketResult =(GetBucketObjectVersionsResult) result;if (getBucketResult.listVersionResult.isTruncated) {// Indicates that data is truncated and the next page of data needs to be fetched.prevPageResult = getBucketResult;}}// If you call the API using kotlin, note that the exception in the callback method must be nullable. Otherwise, the onFail method will not be called, as follows:// The type of clientException is CosXmlClientException?, and the type of serviceException is CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários