Vercel Blob 私有存储开启公开测试,支持鉴权访问敏感文件

1 分钟阅读
2026 年 2 月 19 日
Vercel Blob 现已支持私有存储,适用于合同、发票和内部报告等敏感文件。私有存储要求所有操作都经过认证,从而避免数据通过公开 URL 暴露。
公开存储允许对媒体资源进行公开读取,而私有存储则要求认证后才能访问。
你可以通过 Storage dashboard 创建私有 store,或使用 CLI:
CLI command
vercel blob create-store [name] --access private
当你在已关联的 Vercel 项目中创建 store 时,CLI 会提示你连接该 store,并自动添加 BLOB_READ_WRITE_TOKEN 环境变量。SDK 会使用这个变量为部署中的操作完成认证。
SDK installation
pnpm add @vercel/blob@2.3
上传时,使用 put 或 upload,并设置 access: 'private' 选项。
Upload example
upload.ts
import { put } from '@vercel/blob';export async function POST(request: Request) { // Your auth goes here: await authRequest(req) const filename = request.nextUrl.searchParams.get('filename'); const blob = await put(filename, request.body, { access: 'private', }); return Response.json(blob);}
下载时,使用 get 方法以流的方式返回文件。
Retrieval example
retrieve.ts
import { get } from '@vercel/blob';export async function GET(req: Request) { // Your auth goes here: await authRequest(req) const filename = req.nextUrl.searchParams.get('filename'); const { stream, blob } = await get(filename, { access: "private", }); return new Response(stream, { headers: { "Content-Type": blob.contentType, }, });}
私有存储目前已在所有套餐中以 beta 形式提供,价格沿用标准的 Vercel Blob pricing。
原文链接:https://vercel.com/changelog/private-storage-for-vercel-blob-now-available-in-public-beta

