tencent cloud

Cloud Object Storage

Set Custom Header

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 2026-02-05 10:55:19

Introduction

This document describes how to include custom headers in SDK requests.

Feature Description

COS can include custom headers starting with x-cos-meta- when objects are uploaded, including user-defined metadata header suffixes and user-defined metadata information, and these headers will be saved as object metadata.
If you have enabled the CI service, you can include the Pic-Operations header to implement automatic background image processing. For detailed API descriptions, see CI persistence.

Sample Code

// The bucket region can be viewed on the specified bucket's overview page in the COS console at https://console.tencentcloud.com/cos5/bucket/, for details about regions, see https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1
let region = "ap-beijing"; // your bucket region
// Bucket name, which consists of bucketname-appid (appid must be included), can be viewed in the COS console. https://console.tencentcloud.com/cos5/bucket
let bucket = "examplebucket-1250000000";
//The location identifier of an object in a bucket, also known as the object key
let cosPath = "exampleobject.txt";

let commonHeaderKey = "commonexamplekey"; // custom common Header key
let commonHeaderValue = "commonexamplevalue"; // custom common Header value
let requestHeaderKey = "requestexamplekey"; // custom request Header key
let requestHeaderValue = "requestexamplevalue"; // custom request Header value
// COS service configuration let cosXmlServiceConfig = new CosXmlServiceConfig(region); // Add a common custom Header to all requests cosXmlServiceConfig.headers = new Map(); cosXmlServiceConfig.headers.set(commonHeaderKey, commonHeaderValue);
// Add a custom Header to a single request, which has higher priority than the common Header
let request = new HeadObjectRequest(bucket, cosPath);
request.addHeader(requestHeaderKey, requestHeaderValue);
// Instantiate the COS service cosXmlBaseService let cosXmlBaseService = new CosXmlBaseService(context, cosXmlServiceConfig, credential); try { let result = await cosXmlBaseService.headObject(request) } catch (e) { // Exception handling }


Ajuda e Suporte

Esta página foi útil?

comentários