@edgestore/server

中文文档
1.0.1发布于 2026/10/24MITTypeScriptES Module构建来源已验证近 30 天下载 7452

Upload files with ease from React/Next.js

原始使用文档
文档目录8 节
  1. Next.js Setup
  2. Install
  3. Environment Variables
  4. Backend
  5. Frontend
  6. Upload file
  7. Replace file
  8. Delete file

Docs

Check the official documentation for more information.

Quick Start

Next.js Setup

Install

Let's start by installing the required packages.

npm install @edgestore/server @edgestore/react

Environment Variables

Then go to your Dashboard, create a new project and copy the keys to your environment variables.

EDGESTORE_ACCESS_KEY=your-access-key
EDGESTORE_SECRET_KEY=your-secret-key

Backend

Now we can create the backend code for our Next.js app.
EdgeStore is compatible with both types of Next.js apps (pages router and app router).

The example below is the simplest bucket you can create with EdgeStore. Just a simple file bucket with no validation that will be accessible by anyone with the link.

You can have multiple buckets in your app, each with its own configuration.

import { initEdgeStore } from '@edgestore/server';
import { createEdgeStoreNextHandler } from '@edgestore/server/adapters/next/app';

const es = initEdgeStore.create();

/**
 * This is the main router for the EdgeStore buckets.
 */
const router = es.router({
  publicFiles: es.fileBucket(),
});

const handler = createEdgeStoreNextHandler({
  router,
});

export { handler as GET, handler as POST };

/**
 * This type is used to create the type-safe client for the frontend.
 */
export type EdgeStoreRouter = typeof router;

Frontend

Now let's initiate our context provider.

'use client';

import { createEdgeStoreProvider } from '@edgestore/react';
import { type EdgeStoreRouter } from '../app/api/edgestore/[...edgestore]/route';

const { EdgeStoreProvider, useEdgeStore } =
  createEdgeStoreProvider<EdgeStoreRouter>();

export { EdgeStoreProvider, useEdgeStore };

And then wrap our app with the provider.

import { EdgeStoreProvider } from '../lib/edgestore';
import './globals.css';

// ...

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        <EdgeStoreProvider>{children}</EdgeStoreProvider>
      </body>
    </html>
  );
}

Upload file

You can use the useEdgeStore hook to access a typesafe frontend client and use it to upload files.

import * as React from 'react';
import { useEdgeStore } from '../lib/edgestore';

export default function Page() {
  const [file, setFile] = React.useState<File>();
  const { edgestore } = useEdgeStore();

  return (
    <div>
      <input
        type="file"
        onChange={(e) => {
          setFile(e.target.files?.[0]);
        }}
      />
      <button
        onClick={async () => {
          if (file) {
            const res = await edgestore.publicFiles.upload({
              file,
              onProgressChange: (progress) => {
                // you can use this to show a progress bar
                console.log(progress);
              },
            });
            // you can run some server action or api here
            // to add the necessary data to your database
            console.log(res);
          }
        }}
      >
        Upload
      </button>
    </div>
  );
}

Replace file

By passing the replaceTargetUrl option, you can replace an existing file with a new one. It will automatically delete the old file after the upload is complete.

You can also upload the file using the same file name, but in that case, you might still see the old file for a while because of the CDN cache.

Both ways delete the old file, so the bucket needs beforeDelete, just like deleting.

const res = await edgestore.publicFiles.upload({
  file,
  options: {
    replaceTargetUrl: oldFileUrl,
  },
  // ...
});

Delete file

await edgestore.publicFiles.delete({
  url: urlToDelete,
});

版本与发布记录

@edgestore/server 共发布 76 个版本,首次发布于 2023/08/03;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.1latest2026/10/2420 天前
1.0.02026/10/041 个月前
1.0.0-rc.7rc2026/09/281 个月前
1.0.0-rc.62026/09/281 个月前
1.0.0-next.5next2026/09/271 个月前
1.0.0-next.42026/09/221 个月前

其他发布通道:canary → 0.0.0-canary-20260801075232,next → 1.0.0-next.5,rc → 1.0.0-rc.7。

关于 @edgestore/server 的常见问题

@edgestore/server 是什么?

Upload files with ease from React/Next.js

如何安装 @edgestore/server?

在项目目录运行 npm install @edgestore/server,或使用 pnpm add / yarn add / bun add。

@edgestore/server 支持 TypeScript 吗?

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

@edgestore/server 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@edgestore/server 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.22.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@edgestore/server 可以商用吗?

@edgestore/server 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@edgestore/server 的下载量有多少?

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

@edgestore/server 还在维护吗?

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