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-01-23 17:15:08

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 objects and their version history
Queries some or all the objects in a bucket and their version history.

SDK API References

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

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

Objective-C
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
request.bucket = @"examplebucket-1250000000";

// Maximum number of objects to return at a time. Default value: 1000
request.maxKeys = 100;

// Prefix match, which is used to specify the address prefix of the returned files
request.prefix = @"dir1/";

[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {
// result contains the request result
// `QCloudListBucketResult.contents` is the array of files in the bucket
// `QCloudListBucketResult.commonPrefixes` is the array of folders in the bucket
if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be pulled
self->prevPageResult = result;
}
}];

[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
Note:
For the complete sample, go to GitHub.
Swift
let getBucketReq = QCloudGetBucketRequest.init();

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
getBucketReq.bucket = "examplebucket-1250000000";

// Maximum number of objects to return at a time. Default value: 1000
getBucketReq.maxKeys = 100;

// Prefix match
getBucketReq.prefix = "dir/";

getBucketReq.setFinish { (result, error) in
if let result = result {
// Object list
let contents = result.contents

if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be requested
self.prevPageResult = result;
}
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
Note:
For the complete sample, go to GitHub.

Sample 2. Requesting the next page of data

Objective-C
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
request.bucket = @"examplebucket-1250000000";

// prevPageResult is the result returned on the previous page
// Paging parameter. By default, entries are listed in UTF-8 binary order starting with the marker
request.marker = prevPageResult.nextMarker;

// Maximum number of objects to return at a time. Default value: 1000
request.maxKeys = 100;

[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {
// result contains the request result.
// `QCloudListBucketResult.contents` is the array of files in the bucket
// `QCloudListBucketResult.commonPrefixes` is the array of folders in the bucket
if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be pulled
self->prevPageResult = result;
}
}];

[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
Note:
For the complete sample, go to GitHub.
Swift
let getBucketReq = QCloudGetBucketRequest.init();

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
getBucketReq.bucket = "examplebucket-1250000000";

// Paging parameter. By default, entries are listed in UTF-8 binary order starting with the marker
if let result = self.prevPageResult {
getBucketReq.marker = result.marker
}

// Maximum number of objects to return at a time. Default value: 1000
getBucketReq.maxKeys = 100;
// Prefix match
getBucketReq.prefix = "dir/";

getBucketReq.setFinish { (result, error) in
if let result = result {
// Object list
let contents = result.contents

if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be requested
self.prevPageResult = result;
}
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
Note:
For the complete sample, go to GitHub.

Sample 3. Getting an object list and subdirectories

Objective-C
QCloudGetBucketRequest* request = [QCloudGetBucketRequest new];

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
request.bucket = @"examplebucket-1250000000";

// Maximum number of objects to return at a time. Default value: 1000
request.maxKeys = 100;

// Prefix match, which is used to specify the address prefix of the returned files
request.prefix = @"dir1/";

// The delimiter is a symbol. If the Prefix exists, identical paths between the Prefix and delimiter will be grouped together,
// which is defined as Common Prefix. Then, all common prefixes are listed. If there is no Prefix, the listing starts from the beginning of the path.
// delimiter: path separator, which is fixed to `/`
request.delimiter = @"/";

// prevPageResult is the result returned on the previous page.
// Paging parameter. By default, entries are listed in UTF-8 binary order starting with the marker
request.marker = prevPageResult.nextMarker;

[request setFinishBlock:^(QCloudListBucketResult * result, NSError* error) {
// result contains the request result
// `QCloudListBucketResult.contents` is the array of files in the bucket
// `QCloudListBucketResult.commonPrefixes` is the array of folders in the bucket
if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be pulled.
self->prevPageResult = result;
}
}];

[[QCloudCOSXMLService defaultCOSXML] GetBucket:request];
Note:
For the complete sample, go to GitHub.
Swift
let getBucketReq = QCloudGetBucketRequest.init();

// Bucket name in the format of BucketName-APPID, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket
getBucketReq.bucket = "examplebucket-1250000000";

// Maximum number of objects to return at a time. Default value: 1000
getBucketReq.maxKeys = 100;

// Prefix match, which is used to specify the address prefix of the returned files
getBucketReq.prefix = "dir/";

// The delimiter is a symbol. If the Prefix exists, identical paths between the Prefix and delimiter will be grouped together,
// which is defined as Common Prefix. Then, all common prefixes are listed. If there is no Prefix, the listing starts from the beginning of the path.
// delimiter: path separator, which is always `/`
getBucketReq.delimiter = "/";

// Paging parameter. By default, entries are listed in UTF-8 binary order starting with the marker
if let result = self.prevPageResult {
getBucketReq.marker = result.marker
}

getBucketReq.setFinish { (result, error) in
if let result = result {
// Object list
let contents = result.contents

if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be requested
self.prevPageResult = result;
}
} else {
print(error!);
}
}
QCloudCOSXMLService.defaultCOSXML().getBucket(getBucketReq);
Note:
For the complete sample, go to GitHub.

Querying an Object Version List

Feature description

This API is used to query some or all objects in a versioning-enabled bucket.

Sample code: Getting the first page of data from an object version

QCloudListObjectVersionsRequest* listObjectVersionsRequest = [[QCloudListObjectVersionsRequest alloc] init];

// Bucket Name
listObjectVersionsRequest.bucket = @"bucketname";

// Number of requested data entries per page. Default value: 1000.
listObjectVersionsRequest.maxKeys = 100;

// List the unrequested entries from the current key
listObjectVersionsRequest.keyMarker = prevPageResult.nextKeyMarker;
// List the unrequested entries from an object version in the current key
listObjectVersionsRequest.versionIdMarker = prevPageResult.nextVersionIDMarkder;
[listObjectVersionsRequest setFinishBlock:^(QCloudListVersionsResult * _Nonnull result,
NSError * _Nonnull error) {

// Deleted files
NSArray<QCloudDeleteMarker*> *deleteMarker = result.deleteMarker;

// Number of object version entries
NSArray<QCloudVersionContent*> *versionContent = result.versionContent;

if (result.isTruncated) {
// The data is truncated, and the next page of data needs to be pulled
self->prevPageResult = result;
}


}];

[[QCloudCOSXMLService defaultCOSXML] ListObjectVersions:listObjectVersionsRequest];
Note:
For the complete sample, go to GitHub.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan