Vercel Blob
Last updated:
Vercel Blob Storage
Just need ad-hoc uploads? Wrap this adapter in the
Filesfacade for a one-liner API. The reference below shows direct adapter usage — pick that path when you're hosting an upload server.
Overview
Vercel Blob Storage is a serverless object storage service optimized for edge deployments. It provides fast, global access to files with automatic CDN distribution.
Installation
npm install @vercel/blobyarn add @vercel/blobpnpm add @vercel/blobUsage
On Vercel (recommended): OIDC
When a Blob store is connected to a Vercel project, VERCEL_OIDC_TOKEN and BLOB_STORE_ID are auto-injected. OIDC tokens are short-lived and auto-rotated, so there's no long-lived secret to leak.
import { VercelBlobStorage } from "@visulima/storage/provider/vercel";
// Zero config — picks up VERCEL_OIDC_TOKEN + BLOB_STORE_ID from process.env.
const storage = new VercelBlobStorage({
metaStorageConfig: { directory: "/tmp/upload-metafiles" },
});For runtimes that don't expose process.env (Vite, some edge sandboxes), pass the OIDC pair explicitly:
const storage = new VercelBlobStorage({
oidcToken: loadOidcToken(),
storeId: loadStoreId(), // accepts "store_<id>" or "<id>"
});See Vercel's OIDC docs for the full background.
Off Vercel: read-write token
For CI, local dev, or anything not running on Vercel, use a long-lived BLOB_READ_WRITE_TOKEN:
const storage = new VercelBlobStorage({
token: process.env.BLOB_READ_WRITE_TOKEN,
metaStorageConfig: { directory: "/tmp/upload-metafiles" },
});Configuration
Credential precedence
The adapter resolves auth credentials in this order — first match wins:
- Explicit
tokenoption (RW or client token). - OIDC pair:
oidcToken+storeId(option orVERCEL_OIDC_TOKEN+BLOB_STORE_IDenv). BLOB_READ_WRITE_TOKEN/VERCEL_BLOB_TOKENenv.
If no credentials are found, the constructor throws. Partial OIDC config (only one of oidcToken/storeId set) also throws, so misconfiguration fails loudly instead of silently falling through to anonymous calls.
Environment Variables
| Variable | Purpose |
|---|---|
VERCEL_OIDC_TOKEN | Short-lived OIDC token, auto-injected on Vercel. Must be paired with BLOB_STORE_ID. |
BLOB_STORE_ID | Blob store ID, auto-injected on Vercel. Accepted as store_<id> or <id> (prefix stripped). |
BLOB_READ_WRITE_TOKEN | Long-lived read-write token. Used as a fallback when no OIDC pair is configured. |
VERCEL_BLOB_TOKEN | Alias for BLOB_READ_WRITE_TOKEN, checked second. |
Advanced Configuration
const storage = new VercelBlobStorage({
// Auth (pick one of token / oidcToken+storeId; otherwise env vars are used)
token: process.env.BLOB_READ_WRITE_TOKEN,
multipart: true, // Enable multipart uploads for large files
multipart: 10 * 1024 * 1024, // Or: enable multipart for files > 10MB
retryConfig: {
maxRetries: 3,
initialDelay: 1000,
},
expiration: {
maxAge: "7d",
purgeInterval: "1h",
},
});Peer dependency
OIDC support requires @vercel/blob >= 2.4.0 (the first release with oidcToken and storeId on BlobCommandOptions).
Features
- Global CDN: Automatic CDN distribution for fast access
- Serverless: Optimized for edge deployments
- Multipart Uploads: Support for large files
- Automatic Retry: Built-in retry mechanism for transient failures
Basic Operations
// Create a file
const file = await storage.create({
contentType: "image/jpeg",
metadata: { filename: "photo.jpg" },
});
// Write data
await storage.write({
id: file.id,
body: imageStream,
contentLength: imageSize,
});
// Get file
const fileData = await storage.get({ id: file.id });
// Delete file
await storage.delete({ id: file.id });URL Generation
Vercel Blob automatically generates public URLs:
const file = await storage.get({ id: "file-id" });
// file.url - Public URL
// file.downloadUrl - Download URL
// file.pathname - File pathnameBest Practices
- Prefer OIDC on Vercel - Use
VERCEL_OIDC_TOKEN+BLOB_STORE_IDover long-livedBLOB_READ_WRITE_TOKEN. OIDC tokens auto-rotate and can't leak from a checked-in env file. - Use environment variables - Store tokens securely off Vercel.
- Enable multipart for large files - Better performance for files > 10MB.
- Configure retry - Handle transient failures.
- Use CDN URLs - Leverage Vercel's global CDN.
- Monitor usage - Track storage and bandwidth usage.