tencent cloud

All product documents
Cloud Object Storage
Extracting Object Content
Last updated: 2024-02-02 14:36:36
Extracting Object Content
Last updated: 2024-02-02 14:36:36

Overview

This document provides an overview of APIs and SDK code samples related to object content extraction.
API
Operation
Description
Extracting object content
Extracts the content of a specified object (in CSV or JSON format)

Extracting Object Content

Description

COS Select supports extracting content from 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:
To use COS Select, you must have the permission on cos:GetObject.
CSV and JSON objects need to be encoded in UTF-8.
COS Select can extract CSV and JSON objects compressed by gzip or bzip2.
COS Select can extract CSV and JSON objects encrypted with SSE-COS.

Sample code

try
{
// Bucket name in the format of bucketname-APPID. You can get APPID by referring to https://console.tencentcloud.com/developer.
string bucket = "examplebucket-1250000000";
string key = "exampleobject"; // Object key

SelectObjectRequest request = new SelectObjectRequest(bucket, key);

ObjectSelectionFormat.JSONFormat jSONFormat = new ObjectSelectionFormat.JSONFormat();
jSONFormat.Type = "DOCUMENT";
jSONFormat.RecordDelimiter = "\\n";

string outputFile = "select_local_file.json";

request.SetExpression("Select * from COSObject")
.SetInputFormat(new ObjectSelectionFormat(null, jSONFormat))
.SetOutputFormat(new ObjectSelectionFormat(null, jSONFormat))
.SetCosProgressCallback(delegate (long progress, long total) {
Console.WriteLine("OnProgress : " + progress + "," + total);
})
.OutputToFile(outputFile)
;

SelectObjectResult selectObjectResult = cosXml.SelectObject(request);
Console.WriteLine(selectObjectResult.stat);
}
catch (COSXML.CosException.CosClientException clientEx)
{
Console.WriteLine("CosClientException: " + clientEx.StackTrace);
Console.WriteLine("CosClientException: " + clientEx.Message);
}
catch (COSXML.CosException.CosServerException serverEx)
{
Console.WriteLine("CosServerException: " + serverEx.GetInfo());
}
Note:
For the complete sample, go to GitHub.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon