tencent cloud

Cloud Object Storage

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Use Cases
Strengths
Concepts
Regions and Access Endpoints
Specifications and Limits
Service Regions and Service Providers
Billing
Billing Overview
Billing Method
Billable Items
Free Tier
Billing Examples
Viewing and Downloading Bill
Payment Overdue
FAQs
Getting Started
Console
Getting Started with COSBrowser
User Guide
Creating Request
Bucket
Object
Data Management
Batch Operation
Global Acceleration
Monitoring and Alarms
Operations Center
Data Processing
Content Moderation
Smart Toolbox
Data Processing Workflow
Application Integration
User Tools
Tool Overview
Installation and Configuration of Environment
COSBrowser
COSCLI (Beta)
COSCMD
COS Migration
FTP Server
Hadoop
COSDistCp
HDFS TO COS
GooseFS-Lite
Online Tools
Diagnostic Tool
Use Cases
Overview
Access Control and Permission Management
Performance Optimization
Accessing COS with AWS S3 SDK
Data Disaster Recovery and Backup
Domain Name Management Practice
Image Processing
Audio/Video Practices
Workflow
Direct Data Upload
Content Moderation
Data Security
Data Verification
Big Data Practice
COS Cost Optimization Solutions
Using COS in the Third-party Applications
Migration Guide
Migrating Local Data to COS
Migrating Data from Third-Party Cloud Storage Service to COS
Migrating Data from URL to COS
Migrating Data Within COS
Migrating Data Between HDFS and COS
Data Lake Storage
Cloud Native Datalake Storage
Metadata Accelerator
GooseFS
Data Processing
Data Processing Overview
Image Processing
Media Processing
Content Moderation
File Processing Service
File Preview
Troubleshooting
Obtaining RequestId
Slow Upload over Public Network
403 Error for COS Access
Resource Access Error
POST Object Common Exceptions
API Documentation
Introduction
Common Request Headers
Common Response Headers
Error Codes
Request Signature
Action List
Service APIs
Bucket APIs
Object APIs
Batch Operation APIs
Data Processing APIs
Job and Workflow
Content Moderation APIs
Cloud Antivirus API
SDK Documentation
SDK Overview
Preparations
Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Flutter SDK
Go SDK
iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
React Native SDK
Mini Program SDK
Error Codes
Harmony SDK
Endpoint SDK Quality Optimization
Security and Compliance
Data Disaster Recovery
Data Security
Cloud Access Management
FAQs
Popular Questions
General
Billing
Domain Name Compliance Issues
Bucket Configuration
Domain Names and CDN
Object Operations
Logging and Monitoring
Permission Management
Data Processing
Data Security
Pre-signed URL Issues
SDKs
Tools
APIs
Agreements
Service Level Agreement
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Listing Objects

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-02-04 16:51:44

Overview

This document provides an overview of APIs and SDK code samples for listing objects.
API
Operation
Description
Querying an object list
Queries some or all objects in a bucket

Querying an Object List

Feature description

This API is used to query some or all the objects in a bucket.

Sample 1. Getting the first page of data

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.
let bucket = "examplebucket-1250000000";
try {
let bucketContents: BucketContents = await Cos.getDefaultService().getBucket(
bucket,
{
prefix: "dir/", // Prefix match, which is used to specify the address prefix of returned objects.
maxKeys: 100 // Maximum number of entries returned at a time. Default value: 1000.
}
);
// The data is truncated, and the next page of data needs to be pulled.
let isTruncated = bucketContents.isTruncated;
// `nextMarker` indicates the start position of the next page
let nextMarker = bucketContents.nextMarker;
} catch (e) {
// An exception will be reported in case of failure. Process the business logic accordingly.
console.log(e);
}

Sample 2. Requesting the next page of data

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.
let bucket = "examplebucket-1250000000";
// `prevPageBucketContents` is the result returned on the previous page, where `nextMarker` indicates the start position of the next page
let prevPageMarker = prevPageBucketContents.nextMarker;
try {
let bucketContents: BucketContents = await Cos.getDefaultService().getBucket(
bucket,
{
prefix: "dir/", // Prefix match, which is used to specify the address prefix of returned objects.
marker: prevPageMarker, // Starting position
maxKeys: 100 // Maximum number of entries returned at a time. Default value: 1000.
}
);
// The data is truncated, and the next page of data needs to be pulled.
let isTruncated = bucketContents.isTruncated;
// `nextMarker` indicates the start position of the next page
let nextMarker = bucketContents.nextMarker;
} catch (e) {
// An exception will be reported in case of failure. Process the business logic accordingly.
console.log(e);
}

Sample 3. Getting an object list and subdirectories

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket.
let bucket = "examplebucket-1250000000";
// The delimiter is a symbol. If the prefix exists,
// identical paths between the prefix and delimiter will be grouped as together and defined as a common prefix,
// and then all common prefixes are listed. If there is no prefix, the listing starts from the beginning of the path
let delimiter = "/";
try {
let bucketContents: BucketContents = await Cos.getDefaultService().getBucket(
bucket,
{
prefix: "dir/", // Prefix match, which is used to specify the address prefix of returned objects.
delimiter: delimiter,
maxKeys: 100 // Maximum number of entries returned at a time. Default value: 1000.
}
);
// The data is truncated, and the next page of data needs to be pulled.
let isTruncated = bucketContents.isTruncated;
// `nextMarker` indicates the start position of the next page
let nextMarker = bucketContents.nextMarker;
} catch (e) {
// An exception will be reported in case of failure. Process the business logic accordingly.
console.log(e);
}

Parameter description

Parameter
Description
Type
Required
bucket
Bucket name in the format of BucketName-APPID. For more information, see Bucket Overview.
String
Yes
prefix
Key prefix to query objects by
String
No
delimiter
Character delimiter used to group object keys. Keys that contain identical paths between the prefix (or, if no prefix is specified, the beginning of the string) and the first delimiter are grouped and defined as a Prefix node under CommonPrefixes. The grouped object keys will no longer appear in the subsequent object list. For specific scenarios and usage, see the samples above.
String
No
encodingType
Indicates the encoding method of the returned value. Valid value: url, which means that the returned object keys are URL-encoded (percent-encoded) values. For example, "Tencent Cloud" will be encoded as %E8%85%BE%E8%AE%AF%E4%BA%91.
String
No
marker
Marker for the starting object key. Object key entries will be returned in UTF-8 lexicographical order, starting from the first object key after the marker.
String
No
maxKeys
The maximum number (up to 1,000) of keys returned in the response. Default value: 1000. Note: This parameter limits the maximum number of keys (the sum of CommonPrefixes and Contents) COS can return in each List Objects response. If not all objects are listed in a single response, COS will return the NextMarker node, the value of which can be used to specify marker so that the remaining objects can be listed in your next request.
Int
No

Response description

Success: BucketContents is returned, including the list of objects and list information.
Failure: An error (such as authentication failure) occurs, with a CosXmlClientError or CosXmlServiceError exception reported. For more information, see Troubleshooting.
Parameters in the BucketContents response body are as follows:
Parameter
Description
Type
name
Bucket name in the format of <BucketName-APPID>, such as examplebucket-1250000000.
String
encodingType
Encoding type, which corresponds to the encodingType parameter in the request. This node will be returned only when the encodingType parameter is specified in the request.
String
prefix
Matching prefix to filter object keys. This node corresponds to the Prefix parameter in the request.
String
marker
Marks the object key to start with. Object keys after the marker will be returned in UTF-8 lexicographical order. This node corresponds to the marker parameter in the request.
String
maxKeys
Maximum number of keys returned in a single response. This node corresponds to the maxKeys parameter in the request.
Int
delimiter
Delimiter, which corresponds to the delimiter parameter in the request and will be returned only if the delimiter parameter is specified in the request.
String
isTruncated
Whether the returned list is truncated, which is a Boolean value. Valid values: true, false
Bool
nextMarker
This node will be returned only if the returned list is truncated (i.e., the value of IsTruncated is true). The value of this node is the last object key in the current response. If you need to request subsequent entries, the value can be passed in as the value of the marker parameter in the next request.
String
contentsList
List of objects
List<Content>
commonPrefixesList
The identical paths between the prefix (or, if no prefix is specified, the beginning of the string) and the first delimiter are grouped and defined as a common prefix. This node will be returned only if the delimiter parameter is specified in the request.
List<CommonPrefixes>
Content has the following sub-nodes:
Parameter
Description
Type
key
Object key
String
lastModified
Last modified time of the object, in ISO 8601 format, for example, 2019-05-24T10:56:40Z
String
eTag
Entity tag of the object. It indicates the content of the object when it is created and can be used to verify whether the object content is changed, for example, "8e0b617ca298a564c3331da28dcb50df". The value of ETag is not necessarily the MD5 checksum of the object. The value will be different if the uploaded object is encrypted.
String
size
Object size in bytes
Int
owner
Object owner information
Owner
storageClass
Object storage class, such as STANDARD_IA and ARCHIVE. For enumerated values, see Storage Class.
String
Owner has the following sub-nodes:
Parameter
Description
Type
id
APPID of the object owner
String
disPlayName
Name of the object owner
String
CommonPrefixes has the following sub-nodes:
Parameter
Description
Type
prefix
A single common prefix
String

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan