This document provides an overview of the API and SDK code samples related to extracting object content.
API | Operation | Description |
---|---|---|
SELECT Object Content | Extracting object content | Extracts the content of a specified object (in CSV or JSON format) |
For the parameters and method descriptions of all the APIs in the SDK, please see SDK API Reference.
This API is used by the COS Select feature to extract objects in the following formats:
Note that to use COS Select, you must have the permission to cos:GetObject
.
Note:
CSV- or JSON-formatted objects need to be encoded in UTF-8.
COS Select can extract CSV- or JSON-formatted objects compressed by gzip or bzip2.
COS Select can extract CSV- or JSON-formatted objects encrypted with SSE-COS.
String bucket = "examplebucket-1250000000";
// The object must be in JSON or CSV format
String cosPath = "exampleobject";
final String expression = "Select * from COSObject";
SelectObjectContentRequest selectObjectContentRequest = new SelectObjectContentRequest(
bucket, cosPath, expression, true,
new InputSerialization(CompressionType.NONE, new JSONInput(JSONType.DOCUMENT)),
new OutputSerialization(new JSONOutput(","))
);
// Set the result callback which may work repeatedly
selectObjectContentRequest.setSelectObjectContentProgressListener(new SelectObjectContentListener() {
@Override
public void onProcess(SelectObjectContentEvent event) {
}
});
cosXmlService.selectObjectContentAsync(selectObjectContentRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
SelectObjectContentResult selectObjectContentResult =
(SelectObjectContentResult) result;
}
@Override
public void onFail(CosXmlRequest cosXmlRequest,
CosXmlClientException clientException,
CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});
Note:
For the complete sample, please go to GitHub.
Was this page helpful?