Vercel Blob 私有存储,现已在公开测试版中提供
发布: (2026年2月19日 GMT+8 21:00)
2 分钟阅读
原文: Vercel Blog
Source: Vercel Blog
概览
Vercel Blob 现已支持对合同、发票和内部报告等敏感文件的私有存储。私有存储要求对所有操作进行身份验证,防止通过公共 URL 暴露。
公共存储仍然允许对媒体资产进行公开读取,而私有存储则必须进行身份验证。
创建私有存储
通过 Storage 仪表板 或使用 CLI 创建私有存储:
vercel blob create-store [name] --access private
私有存储需要 BLOB_READ_WRITE_TOKEN 环境变量,该变量在使用 SDK 时会自动注入。
SDK 安装
pnpm add @vercel/blob@2.3
上传文件
使用 put(或 upload)并设置 access: 'private' 选项。
import { put } from '@vercel/blob';
export async function POST(request: Request) {
// Your auth goes here: await authRequest(request);
const filename = request.nextUrl.searchParams.get('filename');
const blob = await put(filename, request.body, {
access: 'private',
});
return Response.json(blob);
}
下载文件
使用 get 方法流式传输文件。
import { get } from '@vercel/blob';
export async function GET(request: Request) {
// Your auth goes here: await authRequest(request);
const filename = request.nextUrl.searchParams.get('filename');
const { stream, blob } = await get(filename, {
access: 'private',
});
return new Response(stream, {
headers: {
'Content-Type': blob.contentType,
},
});
}
定价与可用性
私有存储在所有计划中均为 beta 版,遵循标准的 Vercel Blob 定价。