Extracting Object Content

Last updated: 2021-12-22 12:38:18


    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)

    SDK API Reference

    For the parameters and method descriptions of all the APIs in the SDK, please see SDK API Reference.

    Extracting object content

    API description

    This API is used by the COS Select feature to extract objects in the following formats:

    • CSV: an object is stored in CSV format with its data records separated with a specific delimiter.
    • JSON: an object is stored in JSON format, which can be either a JSON file or a JSON list.

    • To use COS Select, you must have the permission to cos:GetObject.
    • 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.

    Sample code

    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() {
       public void onProcess(SelectObjectContentEvent event) {
           new CosXmlResultListener() {
       public void onSuccess(CosXmlRequest request, CosXmlResult result) {
           SelectObjectContentResult selectObjectContentResult =
                   (SelectObjectContentResult) result;
       public void onFail(CosXmlRequest cosXmlRequest,
                          CosXmlClientException clientException,
                          CosXmlServiceException serviceException) {
           if (clientException != null) {
           } else {

    For the complete sample, please go to GitHub.