tencent cloud

Cloud Object Storage

Querying Object Metadata

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

Introduction

This document provides example code and descriptions for querying object metadata using the COS Android SDK.

Must-Knows

To query the metadata of a target object, you must have read permission for that object. When you configure an authorization policy, the action must be set to cos:HeadObject. For more authorization information, see CAM-supported business APIs.

Related Examples

Feature Name
Description
Example code
Querying Metadata of Objects
Provides the feature of querying object metadata.

Preliminary Preparation

Creating a CosXmlService

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

Use Cases

Query the metadata of an Object.
String bucket = "examplebucket-1250000000"; // Bucket name. Format: BucketName-APPID
String cosPath = "exampleobject"; // The location identifier of the object in the bucket, i.e., the object key.
HeadObjectRequest headObjectRequest = new HeadObjectRequest(bucket, cosPath);
cosXmlService.headObjectAsync(headObjectRequest, new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult result) {
HeadObjectResult headObjectResult = (HeadObjectResult) 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 querying object metadata, see the HEAD Object document.

Ajuda e Suporte

Esta página foi útil?

comentários