Extracting Object Content

Last updated: 2020-09-07 16:16:16

    Overview

    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.

    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.

    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() {
        @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?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help