Skip to content
Files SDK
Esc
navigateopen⌘Jpreview
On this page

Tencent Cloud Object Storage

Tencent Cloud Object Storage (COS) via the S3-compatible API. Endpoint derived from the region code; bucket name must include the -<appid> suffix.

Installation

@aws-sdk/client-s3, @aws-sdk/s3-presigned-post, and @aws-sdk/s3-request-presigner are optional peer dependencies of files-sdk - install alongside the SDK so the adapter’s imports resolve at runtime.

npm install files-sdk @aws-sdk/client-s3 @aws-sdk/s3-presigned-post @aws-sdk/s3-request-presigner
pnpm add files-sdk @aws-sdk/client-s3 @aws-sdk/s3-presigned-post @aws-sdk/s3-request-presigner
yarn add files-sdk @aws-sdk/client-s3 @aws-sdk/s3-presigned-post @aws-sdk/s3-request-presigner
bun add files-sdk @aws-sdk/client-s3 @aws-sdk/s3-presigned-post @aws-sdk/s3-request-presigner

Usage

import { Files } from "files-sdk";
import { tencent } from "files-sdk/tencent";

const files = new Files({
  adapter: tencent({
    bucket: "uploads-1250000000", // <name>-<appid>
    region: "ap-guangzhou", // or "ap-shanghai", "na-siliconvalley", ...
    // accessKeyId / secretAccessKey auto-loaded from
    // TENCENT_SECRET_ID / TENCENT_SECRET_KEY
  }),
});

Tencent Cloud Object Storage (COS) via its S3-compatible API. A thin wrapper around the S3 adapter - endpoint derived from the region code (ap-guangzhou, ap-shanghai, na-siliconvalley, …), virtual-hosted-style addressing, errors relabelled. Auto-loads from TENCENT_SECRET_ID and TENCENT_SECRET_KEY. Generate API keys in the Tencent Cloud console under Cloud Access Management -> API Keys.

Options

PropType
bucketstring

Tencent COS bucket name — must already include the `-<appid>` suffix (e.g. `uploads-1250000000`). COS bucket names are globally namespaced by `<name>-<appid>` and the S3-compatible API expects the full form.

Typestring
regionstring

Tencent COS region, e.g. `"ap-guangzhou"`, `"ap-shanghai"`, `"ap-beijing"`, `"ap-singapore"`, `"na-siliconvalley"`, `"eu-frankfurt"`. Drives the endpoint host (`https://cos.<region>.myqcloud.com`); there's no env-var fallback. Doubles as the SigV4 region. Buckets live in exactly one region.

Typestring
endpoint?string

Override the Tencent COS endpoint. When unset, defaults to `https://cos.${region}.myqcloud.com`. COS routes by Host header — the SDK prepends the bucket subdomain for virtual-hosted style.

Typestring
accessKeyId?string

Static access key ID. Falls back to `TENCENT_SECRET_ID`; required if that env var isn't set.

Typestring
secretAccessKey?string

Static secret access key. Falls back to `TENCENT_SECRET_KEY`; required if that env var isn't set.

Typestring
forcePathStyle?boolean

Use path-style addressing (`/<bucket>/<key>`) rather than virtual-hosted style. Defaults to `false` — virtual-hosted is canonical for Tencent COS.

Typeboolean
publicBaseUrl?string

Origin used to build URLs from `url()`. When set, `url(key)` returns `${publicBaseUrl}/${key}` and skips signing. For public buckets the natural value is `https://${bucket}.cos.${region}.myqcloud.com`; a CDN domain bound to the bucket also works. When unset, `url()` falls back to a presigned GetObject (default expiry: 1 hour).

Typestring
defaultUrlExpiresIn?number

Default expiry, in seconds, for the presigned URLs returned by `url()` when `publicBaseUrl` is not set. Defaults to 3600 (1 hour).

Typenumber

Compatibility

Method Status Notes
upload
download
delete
list
search
head
exists
copy
url
signedUploadUrl

Was this page helpful?