@edgeone/pages-blob

中文文档
0.0.19发布于 2026/11/07MITTypeScriptCommonJS零依赖近 30 天下载 6.7万

Blob storage SDK for EdgeOne Pages functions

原始使用文档
文档目录18 节
  1. Installation
  2. Usage
  3. Inside Pages Functions (automatic authentication)
  4. External access (API Token mode)
  5. Strong consistency (read-after-write)
  6. List all stores
  7. Direct upload from the browser (presigned URL)
  8. API
  9. getStore(name | options)
  10. store.set(key, value, options?)
  11. store.setJSON(key, value, options?)
  12. store.get(key, options?)
  13. store.getWithHeaders(key, options?)
  14. store.delete(key)
  15. store.list(options?)
  16. store.createUploadUrl(key, options?)
  17. listStores(options?)
  18. Quota exceeded

@edgeone/pages-blob

Blob storage SDK for EdgeOne Pages Functions, providing persistent key-value storage across deployments.

Installation

npm install @edgeone/pages-blob

Usage

Inside Pages Functions (automatic authentication)

import { getStore } from "@edgeone/pages-blob";

const store = getStore("my-store");

// Write
await store.set("key", "value");
await store.setJSON("config", { theme: "dark" });

// Read
const text = await store.get("key");
const json = await store.get("config", { type: "json" });

// Delete
await store.delete("key");

// List
const { blobs } = await store.list({ prefix: "users/" });

External access (API Token mode)

When calling from outside Pages Functions, you must supply both token and projectId.

Get your API Token here: https://pages.edgeone.ai/document/api-token

const store = getStore({
  name: "my-store",
  projectId: "makers-urtsvuwmfvli", // required
  token: "c+KH5...", // required
});

Omitting projectId throws MissingProjectIdError.

Strong consistency (read-after-write)

By default reads use eventual consistency (CDN-cached, lower latency). To guarantee read-after-write consistency, use "strong":

// Store-level default — all reads use strong consistency
const store = getStore({ name: "my-store", consistency: "strong" });

// Per-call override
await store.get("key", { consistency: "strong" });
await store.list({ consistency: "strong" });

"eventual" (the default) has lower latency; "strong" guarantees the freshest value at the cost of bypassing the cache layer.

List all stores

import { listStores } from "@edgeone/pages-blob";

// Inside Pages Functions
const { stores } = await listStores();

// External access (token mode) - both fields required
const { stores } = await listStores({
  projectId: "pages-urtsvuwmfvli",
  token: "c+KH5...",
});

Direct upload from the browser (presigned URL)

For large file uploads, hand the browser a presigned PUT URL and let the bytes flow straight to Pages Blob — your function only sees a tiny URL request, not the file itself.

// Function side — generate a one-shot upload URL
import { getStore } from "@edgeone/pages-blob";

export async function onRequest({ request }) {
  const { name } = await request.json();
  const store = getStore("uploads");
  const { url, key, expiresAt } = await store.createUploadUrl(`files/${name}`, {
    expireSeconds: 3600,            // optional, default 3600
    contentType: "application/octet-stream", // optional, binds Content-Type
  });
  return Response.json({ url, key, expiresAt });
}
// Browser side — plain fetch, no SDK needed
const { url, key } = await fetch("/api/get-upload-url", {
  method: "POST",
  body: JSON.stringify({ name: file.name }),
}).then((r) => r.json());

await fetch(url, {
  method: "PUT",
  body: file,                       // File / Blob / ArrayBuffer
  headers: { "Content-Type": "application/octet-stream" }, // must match if `contentType` was set
});
// Bytes go straight from the browser to Pages Blob, never through your Function.

The signature binds the URL to: PUT method, the exact key, the time window, and (optionally) the Content-Type. Other methods, other keys, expired URLs, and mismatched Content-Type all return 403.

API

getStore(name | options)

Get a Store instance.

ParameterTypeDescription
namestringStore name
options.namestringStore name
options.projectIdstringProject ID (required for external access)
options.tokenstringAccess token (required for external access)
options.consistency"eventual" | "strong"Default read consistency (default "eventual")

store.set(key, value, options?)

Write a Blob. value supports string | ArrayBuffer | Blob | ReadableStream.

store.setJSON(key, value, options?)

Write JSON (serialized automatically). Accepts the same options as store.set.

store.get(key, options?)

Read a Blob. Returns null if it does not exist.

  • options.type: "text" (default) | "json" | "arrayBuffer" | "blob" | "stream"
  • options.consistency: "eventual" | "strong" (overrides Store-level default)

store.getWithHeaders(key, options?)

Read a blob along with all response headers. Returns null if the key does not exist.

Returns: { body: string, headers: Record<string, string> }

  • options.consistency: "eventual" | "strong"

store.delete(key)

Delete a Blob.

store.list(options?)

List Blobs. Automatically aggregates all pages by default.

  • options.prefix: prefix filter
  • options.directories: group by directory
  • options.limit: maximum number of blobs to return (default: all)
  • options.paginate: set to false for manual pagination
  • options.cursor: resume from a previous pagination cursor
  • options.consistency: "eventual" | "strong"

Returns: { blobs: Array<{ key, etag }>, directories: string[] }

store.createUploadUrl(key, options?)

Build a presigned PUT URL so a browser/client can upload a file directly to Pages Blob, without the bytes flowing through your function.

ParameterTypeDescription
keystringBlob key
options.expireSecondsnumberValidity window in seconds (default 3600)
options.contentTypestringBind a Content-Type — the client MUST echo this header on its PUT

Returns: { url: string, key: string, expiresAt: number } where expiresAt is a Unix timestamp in seconds.

The URL is bound to PUT + this exact key + the signing time window (and optionally Content-Type). Any other use returns 403.

listStores(options?)

List all Stores under the project.

  • options.projectId: Project ID (required for external access)
  • options.token: Access token (required for external access)
  • options.consistency: "eventual" | "strong"

Returns: { stores: Array<{ name: string }> }

Quota exceeded

When a free-plan blob quota is exceeded, store.set(), store.setJSON() and store.createUploadUrl() throw QuotaExceededError (code: "QUOTA_EXCEEDED") before any bytes are sent.

err.reasonStill works
"storage"reads, deletes
"complex-operations"reads, deletes
"egress"deletes

err.overMetrics lists every metric currently over limit, e.g. ["pages-blob-storage"].

import { QuotaExceededError } from "@edgeone/pages-blob";

try {
  await store.set("key", value);
} catch (err) {
  if (err instanceof QuotaExceededError) {
    // err.reason === "storage" → delete objects or upgrade the plan
  }
}

Usage is checked periodically, so writes can keep succeeding for a few minutes after going over the limit, and keep failing for a few minutes after getting back under it.

A URL from createUploadUrl() that was issued before the quota was exceeded fails on the browser's PUT with 403, 550 or a reset connection; the SDK can't see that response.

版本与发布记录

@edgeone/pages-blob 共发布 19 个版本,首次发布于 2026/05/08;过去 12 个月发布了 19 个版本。

版本发布日期距今
0.0.19latest2026/11/076 天前
0.0.182026/09/251 个月前
0.0.172026/09/241 个月前
0.0.162026/08/063 个月前
0.0.152026/07/313 个月前
0.0.142026/06/264 个月前

关于 @edgeone/pages-blob 的常见问题

@edgeone/pages-blob 是什么?

Blob storage SDK for EdgeOne Pages functions

如何安装 @edgeone/pages-blob?

在项目目录运行 npm install @edgeone/pages-blob,或使用 pnpm add / yarn add / bun add。

@edgeone/pages-blob 支持 TypeScript 吗?

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

@edgeone/pages-blob 支持 ESM 还是 CommonJS?

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

@edgeone/pages-blob 需要什么版本的 Node.js?

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

@edgeone/pages-blob 可以商用吗?

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

@edgeone/pages-blob 的下载量有多少?

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

@edgeone/pages-blob 还在维护吗?

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