@antelopejs/file-storage-local

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

Local filesystem storage module for AntelopeJS, implementing the File Storage interface for development and single-instance deployments

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

@antelopejs/file-storage-local

npm License Discord Documentation

The AntelopeJS file storage module for a single machine. It keeps the files of the file storage interface on the local filesystem and serves signed upload and read URLs through the API module.

Use it for development and for a deployment with one instance, because instances do not share files. For several instances, use @antelopejs/file-storage-s3.

In production, run exactly one instance and put storagePath on a persistent disk. A container's temporary directory loses every file when the instance sleeps, restarts, or is replaced. A second instance never sees the files of the first, so an upload can land on one instance and its confirmation on the other. On AntelopeJS Cloud, attach a volume to the service and point storagePath at its mount path. Attaching a volume keeps the service at one replica. The module cannot tell a persistent disk from a temporary one, so it logs a warning on every start outside dev mode.

Part of AntelopeJS. Used by AntelopeJS DMS, the open-source back office for your PostgreSQL, MongoDB or RethinkDB database.

Interfaces

InterfaceDocumentation
@antelopejs/interface-file-storageFile storage

The interface pages document uploads, reads, visibility, metadata, staging, and promotion. The module serves its routes through @antelopejs/interface-api, implemented by @antelopejs/api.

Install

ajs project modules add @antelopejs/file-storage-local
ajs project modules install

ajs project modules install adds a module for each interface that the project imports and no module implements. For @antelopejs/interface-api, that module is @antelopejs/api. This module ships no default configuration, so add a config block with at least storagePath and baseUrl.

Configuration

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

export default defineConfig({
  name: "my-project",
  modules: {
    "file-storage-local": {
      source: {
        type: "package",
        package: "@antelopejs/file-storage-local",
        version: "^0.1.8",
      },
      config: {
        storagePath: ".antelope/storage",
        baseUrl: "${@api.API_PUBLIC_BASE_URL}",
        defaultVisibility: "private",
        uploadTokenExpiration: 3600,
        readTokenExpiration: 60,
        cleanupInterval: 300,
        stagingExpiration: 86400,
        storages: {
          media: {
            storagePath: ".antelope/media",
            baseUrl: "${@api.API_PUBLIC_BASE_URL}",
            defaultVisibility: "public",
          },
        },
      },
    },
  },
});
KeyDefaultDescription
storagePathrequiredFolder that holds the files.
baseUrlrequiredPublic origin of the API module. Upload and read URLs start with <baseUrl>/file-storage/.
defaultVisibility"private"Visibility of a file uploaded without one, "public" or "private".
uploadTokenExpiration3600Lifetime of an upload URL, in seconds.
readTokenExpiration60Lifetime of a private read URL when CreateReadUrl gets no expiresIn, in seconds.
cleanupInterval300Interval of the expired-token cleanup, in seconds. 0 or less turns the cleanup off.
stagingExpirationnoneWhen set, the cleanup also deletes staged files older than this many seconds. Without it, staged files stay.
storagesnoneNamed storages, each with the keys above except storages. Address one with the storage argument of the interface functions.

A named storage gets the same defaults for the keys it leaves out. The cleanup and the staging sweep run on each storage with its own cleanupInterval and stagingExpiration.

${@api.API_PUBLIC_BASE_URL} is a config variable that @antelopejs/api publishes under the module key api. Storage folders must not overlap, and the storage name default is reserved. The module refuses to start otherwise.

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 the returned upload.headers, then fetches it from read.url.

Platform notes

  • Resource keys and upload paths use / as the separator and stay inside their storage. The module rejects . and .. segments.
  • A generated key keeps the extension of the uploaded file only when the extension has 1 to 16 letters, digits, _, or -.
  • The module publishes files with hard links, so storage folders must be on a filesystem that supports them. On Windows, use NTFS.
  • On Windows, keys that differ only by letter case address the same file. The module rejects segments that Windows cannot store: reserved characters, control characters, a trailing dot or space, and device names such as CON or NUL.

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-api>=0.0.16 <1.0.00.0.16
@antelopejs/interface-core>=0.4.0 <1.0.00.4.0
@antelopejs/interface-file-storage>=0.1.6 <0.2.00.1.6

CI runs the tests on Linux and Windows, with the Node.js release that .nvmrc names.

Contributing

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-local 共发布 17 个版本,首次发布于 2026/03/24;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/11/051 天前
0.1.132026/10/2413 天前
0.1.122026/10/2314 天前
0.1.112026/10/2314 天前
0.1.102026/10/2314 天前
0.1.92026/10/1720 天前

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

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

Local filesystem storage module for AntelopeJS, implementing the File Storage interface for development and single-instance deployments

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

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

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

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

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

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

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

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

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

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

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

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