tencent cloud

masukan

Listing Objects

Terakhir diperbarui:2024-02-02 14:36:36

    Overview

    This document provides an overview of APIs and SDK code samples related to listing objects.
    API
    Operation
    Description
    Querying objects
    Queries some or all the objects in a bucket.
    Querying objects and their version history
    Queries some or all the objects in a bucket and their version history.

    Querying an Object List

    Description

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

    Sample 1. Getting the first page of data

    [//]: # ".cssg-snippet-get-bucket"
    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";
    GetBucketRequest request = new GetBucketRequest(bucket);
    // Execute the request
    GetBucketResult result = cosXml.GetBucket(request);
    // Bucket information
    ListBucket info = result.listBucket;
    if (info.isTruncated) {
    // The data is truncated, and the next marker of the data is recorded.
    this.nextMarker = info.nextMarker;
    }
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.

    Sample 2. Requesting the next page of data

    [//]: # ".cssg-snippet-get-bucket-next-page"
    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";
    GetBucketRequest request = new GetBucketRequest(bucket);
    // Use the “nextMarker” from the previous request
    request.SetMarker(this.nextMarker);
    // Execute the request
    GetBucketResult result = cosXml.GetBucket(request);
    // Bucket information
    ListBucket info = result.listBucket;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.

    Sample 3. Getting an object list and subdirectories

    [//]: # ".cssg-snippet-get-bucket-with-delimiter"
    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";
    GetBucketRequest request = new GetBucketRequest(bucket);
    // Get the objects and subdirectories under “a/”
    request.SetPrefix("a/");
    request.SetDelimiter("/");
    // Execute the request
    GetBucketResult result = cosXml.GetBucket(request);
    // Bucket information
    ListBucket info = result.listBucket;
    // List objects
    List<ListBucket.Contents> objects = info.contentsList;
    // List common prefixes
    List<ListBucket.CommonPrefixes> subDirs = info.commonPrefixesList;
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.

    Querying an Object Version List

    Description

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

    Sample 1. Getting the object version list’s first page of data

    [//]: # ".cssg-snippet-list-objects-versioning"
    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";
    ListBucketVersionsRequest request = new ListBucketVersionsRequest(bucket);
    // Execute the request
    ListBucketVersionsResult result = cosXml.ListBucketVersions(request);
    // Bucket information
    ListBucketVersions info = result.listBucketVersions;
    
    List<ListBucketVersions.Version> objects = info.objectVersionList;
    List<ListBucketVersions.CommonPrefixes> prefixes = info.commonPrefixesList;
    
    if (info.isTruncated) {
    // The data is truncated, and the next marker of the data is recorded.
    this.keyMarker = info.nextKeyMarker;
    this.versionIdMarker = info.nextVersionIdMarker;
    }
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.

    Sample 2. Getting the object version list’s next page of data

    [//]: # ".cssg-snippet-list-objects-versioning-next-page"
    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";
    ListBucketVersionsRequest request = new ListBucketVersionsRequest(bucket);
    
    // Use the “nextMarker” from the previous request
    request.SetKeyMarker(this.keyMarker);
    request.SetVersionIdMarker(this.versionIdMarker);
    
    // Execute the request
    ListBucketVersionsResult result = cosXml.ListBucketVersions(request);
    ListBucketVersions info = result.listBucketVersions;
    
    if (info.isTruncated) {
    // The data is truncated, and the next marker of the data is recorded.
    this.keyMarker = info.nextKeyMarker;
    this.versionIdMarker = info.nextVersionIdMarker;
    }
    }
    catch (COSXML.CosException.CosClientException clientEx)
    {
    // Request failed
    Console.WriteLine("CosClientException: " + clientEx);
    }
    catch (COSXML.CosException.CosServerException serverEx)
    {
    // Request failed
    Console.WriteLine("CosServerException: " + serverEx.GetInfo());
    }
    Note:
    For the complete sample, go to GitHub.
    Hubungi Kami

    Hubungi tim penjualan atau penasihat bisnis kami untuk membantu bisnis Anda.

    Dukungan Teknis

    Buka tiket jika Anda mencari bantuan lebih lanjut. Tiket kami tersedia 7x24.

    Dukungan Telepon 7x24