@antelopejs/file-storage-s3

中文文档
0.1.10发布于 2026/11/04Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 2684

S3-compatible storage module for AntelopeJS (AWS S3, Cloudflare R2), implementing the File Storage interface with presigned URLs

原始使用文档
文档目录9 节
  1. Interfaces
  2. Install
  3. Configuration
  4. Quick start
  5. Before deploying
  6. Documentation
  7. Compatibility
  8. Contributing
  9. License

@antelopejs/file-storage-s3

npm License Discord Documentation

The AntelopeJS file storage module for S3-compatible object storage, such as AWS S3 and Cloudflare R2. It uses @aws-sdk/client-s3, and clients upload and read files directly from the bucket through presigned URLs.

Interfaces

InterfaceDocumentation
@antelopejs/interface-file-storageFile storage

The interface pages document uploads, reads, visibility, metadata, staging, and promotion.

Install

ajs project modules add @antelopejs/file-storage-s3

The module ships no default configuration, so add a config block with a default storage before you start the project.

Configuration

import { defineConfig } from "@antelopejs/interface-core/config";

export default defineConfig({
  name: "my-project",
  modules: {
    "file-storage-s3": {
      source: {
        type: "package",
        package: "@antelopejs/file-storage-s3",
        version: "^0.1.5",
      },
      config: {
        default: {
          endpoint: "https://<account>.r2.cloudflarestorage.com",
          region: "auto",
          accessKeyId: "<access-key-id>",
          secretAccessKey: "<secret-access-key>",
          bucket: "app-files",
          attachmentPrivateBucket: "app-private-files",
          publicUrl: "https://cdn.example.com",
          defaultVisibility: "private",
          defaultUploadExpiration: 3600,
          defaultReadExpiration: 300,
          stagingExpirationDays: 1,
          assumePrivateBuckets: false,
        },
        storages: {
          media: {
            endpoint: "https://<account>.r2.cloudflarestorage.com",
            region: "auto",
            accessKeyId: "<access-key-id>",
            secretAccessKey: "<secret-access-key>",
            bucket: "app-media",
            publicUrl: "https://media.example.com",
            defaultVisibility: "public",
            defaultUploadExpiration: 3600,
            defaultReadExpiration: 300,
          },
        },
      },
    },
  },
  envOverrides: {
    S3_SECRET_ACCESS_KEY:
      "modules.file-storage-s3.config.default.secretAccessKey",
  },
});
KeyDescription
endpoint, regionS3 endpoint and region. R2 uses region auto.
accessKeyId, secretAccessKeyCredentials of the S3 client.
bucketBucket that holds the files.
attachmentPrivateBucketOptional bucket for uploads that request visibility: "private", kept apart from a public bucket. Without it, such an upload throws.
publicUrlOptional public origin of bucket. A public file is read from <publicUrl>/<resourceKey>. Without publicUrl, it is read through a presigned URL.
defaultVisibilityVisibility of a file uploaded without one, "public" or "private".
defaultUploadExpirationLifetime of an upload URL, in seconds.
defaultReadExpirationLifetime of a private read URL, in seconds, when the caller sets none.
stagingExpirationDaysOptional. At startup, the module puts a lifecycle rule on bucket and attachmentPrivateBucket that expires staged files after this many days. Omit it when your infrastructure manages lifecycle rules.
assumePrivateBucketsOptional, false by default. Relaxes the private bucket verification for providers that cannot pass it.

Every key except the optional ones is required. default holds the main storage. storages adds named storages with the same keys, and the storage argument of the interface functions selects one. The name default is reserved in storages, and the module refuses to start with it.

Quick start

In the module that handles uploads, add the interface:

pnpm add @antelopejs/interface-file-storage
import {
  CreateReadUrl,
  CreateUploadUrl,
} from "@antelopejs/interface-file-storage";

const upload = await CreateUploadUrl(
  { filename: "avatar.png", size: 52_000, mimetype: "image/png" },
  { maxSize: 1_000_000, allowedMimetypes: ["image/png", "image/jpeg"] },
);

const read = await CreateReadUrl(upload.resourceKey);

The client sends the file with PUT upload.uploadUrl and every header of upload.headers, unchanged, then fetches it from read.url.

Before deploying

  • Upload URLs sign an If-None-Match: * condition, so an upload never replaces an existing object. The provider must enforce conditional PUT, and the bucket CORS rules must allow the if-none-match header.
  • The module verifies that attachmentPrivateBucket blocks all public access before using it. MinIO and Hetzner Object Storage need assumePrivateBuckets: true.
  • S3 stores metadata keys in lowercase, so GetFileMetadata returns tenantid for an upload sent with tenantId. Two keys that differ only by case make the upload throw.

UPLOADS.md details these guarantees. It covers create-only uploads, promotion, privacy and expiry, private bucket verification, metadata keys, and CORS.

Documentation

  • File storage documents the @antelopejs/interface-file-storage contract that this module implements.
  • Configuration covers module sources, config blocks, and config variables in antelope.config.ts.

Compatibility

PackageSupportedTested with
@antelopejs/interface-core>=0.2.4 <1.0.00.2.4
@antelopejs/interface-file-storage>=0.1.6 <0.2.00.1.6

.nvmrc names the Node.js release for development. The tests run against the Moto image that .github/release-services.yml pins.

Contributing

The tests need a Moto S3 server on 127.0.0.1:5005. Start the one that CI uses:

docker compose -f .github/release-services.yml up -d --wait

Then run the checks:

pnpm install
pnpm lint
pnpm format:check
pnpm knip
pnpm test           # build, then ajs module test

The tests also run the shared conformance suite of @antelopejs/interface-file-storage. Read the contribution guidelines before opening a pull request.

License

Apache-2.0

版本与发布记录

@antelopejs/file-storage-s3 共发布 12 个版本,首次发布于 2026/03/24;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.10latest2026/11/043 天前
0.1.92026/10/2415 天前
0.1.82026/10/2316 天前
0.1.72026/10/2316 天前
0.1.62026/10/1721 天前
0.1.52026/09/301 个月前

关于 @antelopejs/file-storage-s3 的常见问题

@antelopejs/file-storage-s3 是什么?

S3-compatible storage module for AntelopeJS (AWS S3, Cloudflare R2), implementing the File Storage interface with presigned URLs

如何安装 @antelopejs/file-storage-s3?

在项目目录运行 npm install @antelopejs/file-storage-s3,或使用 pnpm add / yarn add / bun add。

@antelopejs/file-storage-s3 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@antelopejs/file-storage-s3 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@antelopejs/file-storage-s3 可以商用吗?

@antelopejs/file-storage-s3 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@antelopejs/file-storage-s3 的下载量有多少?

根据 npm 官方下载统计,@antelopejs/file-storage-s3 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,684 次,日均约 89 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@antelopejs/file-storage-s3 还在维护吗?

最新版本 0.1.10 发布于 2026/11/04(3 天前);至今共发布 12 个版本,其中过去 12 个月发布了 12 个;首次发布于 2026/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。