API | Operation | Description |
Querying an object list | Queries some or all objects in a bucket | |
Querying objects and their version history | Queries some or all the objects in a bucket and their version history. |
String bucketName = "examplebucket-1250000000"; // Format: BucketName-APPID;final GetBucketRequest getBucketRequest = new GetBucketRequest(bucketName);// Prefix match, which is used to specify the address prefix of the returned objectsgetBucketRequest.setPrefix("dir/");// The maximum number of entries returned at a time; the default value is 1,000getBucketRequest.setMaxKeys(100);cosXmlService.getBucketAsync(getBucketRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketResult getBucketResult = (GetBucketResult) result;if (getBucketResult.listBucket.isTruncated) {// The data is truncated, and the next page of data needs to be pulledprevPageResult = getBucketResult;}}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type 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 match, which is used to specify the address prefix of the returned objectsgetBucketRequest.setPrefix("dir/");// `prevPageResult` is the result returned on the previous page, where `nextMarker` indicates the starting point of the next pageString nextMarker = prevPageResult.listBucket.nextMarker;getBucketRequest.setMarker(nextMarker);// The maximum number of entries returned at a time; the default value is 1,000getBucketRequest.setMaxKeys(100);cosXmlService.getBucketAsync(getBucketRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketResult getBucketResult = (GetBucketResult) result;if (getBucketResult.listBucket.isTruncated) {// The data is truncated, and the next page of data needs to be pulled}}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type 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 match, which is used to specify the address prefix of the returned objectsgetBucketRequest.setPrefix("dir/");// The maximum number of entries returned at a time; the default value is 1,000getBucketRequest.setMaxKeys(100);// The delimiter is a symbol. If the prefix exists,// identical paths between the prefix and delimiter will be grouped as together and defined as a common prefix,// and then all common prefixes are listed. If there is no prefix, the listing starts from the beginning of the pathgetBucketRequest.setDelimiter("/");cosXmlService.getBucketAsync(getBucketRequest, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketResult getBucketResult = (GetBucketResult) result;}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type 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 match, which is used to specify the address prefix of the returned objectsgetBucketRequest.setPrefix("dir/");// The maximum number of entries returned at a time; the default value is 1,000getBucketRequest.setMaxKeys(100);cosXmlService.getBucketObjectVersionsAsync(getBucketRequest,new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult result) {GetBucketObjectVersionsResult getBucketResult =(GetBucketObjectVersionsResult) result;if (getBucketResult.listVersionResult.isTruncated) {// The data is truncated, and the next page of data needs to be pulledprevPageResult = getBucketResult;}}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type 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 match, which is used to specify the address prefix of the returned objectsgetBucketRequest.setPrefix("dir/");// The maximum number of entries returned at a time; the default value is 1,000getBucketRequest.setMaxKeys(100);// `prevPageResult` is the result returned on the previous page, where `nextMarker` and `nextVersionIdMarker`// indicate the starting point of the next pagegetBucketRequest.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) {// The data is truncated, and the next page of data needs to be pulledprevPageResult = getBucketResult;}}// If you use the Kotlin language to call this, please note that the exception in the callback method is nullable; otherwise, the onFail method will not be called back, that is:// clientException is of type CosXmlClientException? and serviceException is of type CosXmlServiceException?@Overridepublic void onFail(CosXmlRequest cosXmlRequest,@Nullable CosXmlClientException clientException,@Nullable CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Was this page helpful?