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

Alibaba Cloud OSS

Alibaba Cloud Object Storage Service (OSS) via the S3-compatible API. Endpoint derived from the region code (cn-hangzhou, ap-southeast-1, ...).

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 { alibaba } from "files-sdk/alibaba";

const files = new Files({
  adapter: alibaba({
    bucket: "uploads",
    region: "cn-hangzhou", // or "cn-shanghai", "ap-southeast-1", ...
    // accessKeyId / secretAccessKey auto-loaded from
    // ALIBABA_ACCESS_KEY_ID / ALIBABA_ACCESS_KEY_SECRET
  }),
});

Alibaba Cloud Object Storage Service (OSS) via its S3-compatible API. A thin wrapper around the S3 adapter - endpoint derived from the region code (cn-hangzhou, cn-shanghai, ap-southeast-1, …), virtual-hosted-style addressing, errors relabelled. Auto-loads from ALIBABA_ACCESS_KEY_ID and ALIBABA_ACCESS_KEY_SECRET. Generate AccessKey pairs in the Alibaba Cloud console under RAM -> Users.

Options

PropType
bucketstring

Alibaba OSS bucket name. The adapter scopes all operations to it.

Typestring
regionstring

Alibaba Cloud OSS region, e.g. `"cn-hangzhou"`, `"cn-shanghai"`, `"cn-beijing"`, `"ap-southeast-1"` (Singapore), `"us-east-1"` (Virginia), `"eu-central-1"` (Frankfurt). Drives the endpoint host (`https://oss-<region>.aliyuncs.com`); there's no env-var fallback. Doubles as the SigV4 region (pass the bare region, not the `oss-`-prefixed form). Buckets live in exactly one region.

Typestring
endpoint?string

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

Typestring
accessKeyId?string

Static credentials. Falls back to `ALIBABA_ACCESS_KEY_ID`; required if that env var isn't set.

Typestring
secretAccessKey?string

Static credentials. Falls back to `ALIBABA_ACCESS_KEY_SECRET`; 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 Alibaba OSS.

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}.oss-${region}.aliyuncs.com`; a custom 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?