tencent cloud

Cloud Object Storage

Extracting Object Content

Download
Modo Foco
Tamanho da Fonte
Última atualização: 2026-05-15 15:32:04

Introduction

This document provides example code and descriptions for retrieving object content using the COS Android SDK.

Must-Knows

To use the object content search feature, you must have read permission for the target object. When you configure an authorization policy, set the action to cos:GetObject. For more authorization information, see CAM-supported business APIs.
COS Select supports searching object data in the following formats:
CSV format: Objects are stored in CSV format and delimited by a fixed separator.
JSON format: Objects are stored in JSON format and can be JSON files or JSON lists.
CSV and JSON objects must be encoded in UTF-8 format.
COS Select supports searching CSV and JSON objects compressed with GZIP or BZIP2.
COS Select supports searching CSV and JSON objects encrypted with SSE-COS.

Related Examples

Feature Name
Description
Example code
Search object content.
Retrieve content from specified objects (in CSV, JSON, or Parquet format) using Structured Query Language (SQL).

Preliminary Preparation

Creating a CosXmlService

Before calling a COS API, you must first create a CosXmlService instance. For detailed code, see Creating CosXmlService.

Use Cases

String bucket = "examplebucket-1250000000";
// Objects must be files 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 query result callback, which may be called multiple times.
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;
}

// 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?
@Override
public void onFail(CosXmlRequest cosXmlRequest,
@Nullable CosXmlClientException clientException,
@Nullable CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});

SDK API Reference

For detailed parameters and method descriptions of all SDK interfaces, see SDK API Reference.

API Operations

For the description of the API for searching object content, see the SELECT Object Content document.

Ajuda e Suporte

Esta página foi útil?

comentários