tencent cloud

Cloud Object Storage

OPTIONS Object

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

Introduction

This document provides example code and a description for implementing preflight cross-origin configuration using the COS Android SDK. Preflight cross-origin configuration (Options Object).

Must-Knows

When you configure an authorization policy, set the action to cos:OptionsObject. For more authorization information, see CAM-supported business APIs.

Related Examples

Feature Name
Description
Example code
Checking CORS Configuration
Provides the capability to configure preflight CORS for objects.

Preliminary Preparation

Creating a CosXmlService

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

Use Cases

// A bucket name consists of bucketname-appid. You must include the appid. You can view bucket names in the COS console. https://console.tencentcloud.com/cos5/bucket
String bucket = "examplebucket-1250000000";
String cosPath = "exampleobject"; // The location identifier of the object in the bucket, i.e., the object key.
String origin = "https://cloud.tencent.com";
String accessMethod = "PUT";
OptionObjectRequest optionObjectRequest = new OptionObjectRequest(bucket,
cosPath, origin,
accessMethod);
cosXmlService.optionObjectAsync(optionObjectRequest,
new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest cosXmlRequest, CosXmlResult result) {
OptionObjectResult optionObjectResult = (OptionObjectResult) 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 API descriptions related to the preflight cross-origin configuration interface, see OPTIONS Object.

Ajuda e Suporte

Esta página foi útil?

comentários