# @antelopejs/file-storage-local 中文文档

规范地址：https://npmcn.com/package/%40antelopejs/file-storage-local/

版本：0\.2\.0
npm 元数据更新时间：2026-11-04T19:56:53.992Z
中文译文更新时间：2026-11-06T06:32:18.526Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40antelopejs/file-storage-local
原文对照：https://npmcn.com/package/%40antelopejs/file-storage-local/?lang=original
项目主页：https://github.com/AntelopeJS/interface-file-storage/tree/main/docs
源码仓库：https://github.com/AntelopeJS/file-storage-local

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：279 kB，75 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2026-03-23T18:53:16.489Z
- 最新版本发布：2026-11-04T19:56:53.632Z
- 近 30 天下载量：4897（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：17（近 12 个月 17 个）

## 中文简介

用于羚羊JS的本地文件系统存储模块,实施用于开发的文件存储接口和单机部署

## 安装

```sh
npm install @antelopejs/file-storage-local
```

也可以使用：`pnpm add @antelopejs/file-storage-local`、`yarn add @antelopejs/file-storage-local`、`bun add @antelopejs/file-storage-local`

## README

# `@antelopejs/file-storage-local`

[![npm](https://img.shields.io/npm/v/@antelopejs/file-storage-local?style=for-the-badge&labelColor=000000&color=000000)](https://www.npmjs.com/package/@antelopejs/file-storage-local) [![License](https://img.shields.io/npm/l/@antelopejs/file-storage-local?style=for-the-badge&labelColor=000000&color=000000)](https://npmcn.com/package/%40antelopejs/file-storage-local/LICENSE) [![Discord](https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000)](https://discord.gg/g4pFt6eXqu) [![Documentation](https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000)](https://github.com/AntelopeJS/interface-file-storage/tree/main/docs)

单机的AntelopeJS文件存储模块. 它将文件存储接口的文件保存在本地文件系统中,并通过API模块服务签名上传并读取URL.

用于开发,并用于一个实例的部署,因为实例不共享文件。 对于若干实例,使用 [`@antelopejs/file-storage-s3`](https://github.com/AntelopeJS/file-storage-s3)。 。 。 .

在生产中,运行 完全一个实例并设置 `storagePath` 在一个持续磁盘上。 当实例睡眠,重启,或被替换时,容器的临时目录会丢失每个文件. 二审从不看第一审的档案,所以上传可以降落在一审上,确认可以降落在一审上. 在"羚羊JS"云上,在服务和点上附上一卷 `storagePath` 在它的山道上, 随附一卷能使服务保持在一卷. 模块无法从临时磁盘中分辨出一个持久性磁盘,因此它记录了每一次在dev模式外启动的警告.

部分 [羚羊JS](https://github.com/AntelopeJS/antelopejs)用于 [羚羊JS 隐形物](https://github.com/AntelopeJS/dms),用于您的 PostgreSQL 、 MongoDB 或 RethinkDB 数据库的开源后台.

## 接口

| 接口 | 文档 |
| --- | --- |
| [`@antelopejs/interface-file-storage`](https://github.com/AntelopeJS/interface-file-storage) | [文件存储](https://github.com/AntelopeJS/interface-file-storage/tree/main/docs) |

界面页面文档上传、阅读、能见度、元数据、中继和宣传。 该模块服务于其路线通过 [`@antelopejs/interface-api`](https://interfaces.antelopejs.com/docs/api/introduction),由 [`@antelopejs/api`](https://github.com/AntelopeJS/api)。 。 。 .

## 安装

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

`ajs project modules install` 为项目导入的每个接口增加一个模块,没有模块执行。 对于 `@antelopejs/interface-api`,该模块是 `@antelopejs/api`。本模块没有默认配置,因此添加一个 `config` 至少带有 `storagePath` 财务报告和审定财务报表 `baseUrl`。 。 。 .

## 配置

```typescript
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",
          },
        },
      },
    },
  },
});
```

| 密钥 | 默认 | 说明 |
| --- | --- | --- |
| `storagePath` | 所需经费 | 保存文件的文件夹 . |
| `baseUrl` | 所需经费 | API模块的公开出处. 上传并读取 URL 开始于 `<baseUrl>/file-storage/`。 。 。 . |
| `defaultVisibility` | `"private"` | 上传文件的可见度,没有, `"public"` 或者说 `"private"`。 。 。 . |
| `uploadTokenExpiration` | `3600` | 上传URL的寿命, 以秒计 . |
| `readTokenExpiration` | `60` | 私人读取 URL 的寿命 `CreateReadUrl` 得到没有 `expiresIn`数秒后. |
| `cleanupInterval` | `300` | 中断已过期的托肯清理, 以秒计 . `0` 或更少地把清理关掉. |
| `stagingExpiration` | 无 | 设定时,清理也会删除比这多秒长的已上演的文件. 没有它, 舞台文件就留下. |
| `storages` | 无 | 已命名的存储, 每一个都带有上面的密钥, 除非 `storages`。与 `storage` 参数. |

一个被命名的存储器会得到它漏出键的相同的默认值. 清理和清理每个仓库 `cleanupInterval` 财务报告和审定财务报表 `stagingExpiration`。 。 。 .

`${@api.API_PUBLIC_BASE_URL}` 是一个 [配置变量](https://framework.antelopejs.com/docs/concepts/configuration#module-config-variables) 那个 `@antelopejs/api` 在模块密钥下发布 `api`。存储文件夹不得重叠,存储名称 `default` 预留。 模块拒绝另起炉灶.

## 快开始

在处理上传的模块中,添加接口:

```bash
pnpm add @antelopejs/interface-file-storage
```

```typescript
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);
```

客户端发送文件 `PUT upload.uploadUrl` 返回时 `upload.headers`,然后从 `read.url`。 。 。 .

## 平台注释

-   资源密钥和使用的上传路径 `/` 作为分离者,并停留在他们的储存中。 模块拒绝 `.` 财务报告和审定财务报表 `..` 部分.
-   生成的密钥仅在扩展名有 1 到 16 个字母, 数字时保留上传文件的扩展名 , `_`,或 `-`。 。 。 .
-   模块发布带有硬链接的文件,因此存储文件夹必须在支持它们的文件系统中. 在视窗上,使用NTFS.
-   在Windows上,仅因字母大小写而不同的密钥地址是同一个文件. 模块拒绝 Windows 无法存储的片段: 保留字符、 控制字符、 后端点或空格、 设备名称等 `CON` 或者说 `NUL`。 。 。 .

## 文档

-   [文件存储](https://github.com/AntelopeJS/interface-file-storage/tree/main/docs) 文档 `@antelopejs/interface-file-storage` 与本模块执行的合同.
-   [配置](https://framework.antelopejs.com/docs/concepts/configuration) 包括模块来源, `config` 区块和配置变量 `antelope.config.ts`。 。 。 .

## 兼容性

| 软件包 | 支助 | 测试过 |
| --- | --- | --- |
| `@antelopejs/interface-api` | `>=0.0.16 <1.0.0` | `0.0.16` |
| `@antelopejs/interface-core` | `>=0.4.0 <1.0.0` | `0.4.0` |
| `@antelopejs/interface-file-storage` | `>=0.1.6 <0.2.0` | `0.1.6` |

CI在Linux和Windows上运行测试,由Node.js发布 `.nvmrc` 名称.

## 捐款

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

测试还管理着共用的兼容套件,包括: `@antelopejs/interface-file-storage`。阅读 [捐款准则](https://npmcn.com/package/%40antelopejs/file-storage-local/CONTRIBUTING.md) 在打开拉出请求之前.

## 许可证

[阿帕奇 - 2.0](https://npmcn.com/package/%40antelopejs/file-storage-local/LICENSE)

## 常见问题

### @antelopejs/file-storage-local 是什么？

用于羚羊JS的本地文件系统存储模块,实施用于开发的文件存储接口和单机部署

### 如何安装 @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 和提交记录判断。

