vercel-blob
Vercel Blob object storage with CDN for Next.js. Use for file uploads (images, PDFs, videos), presigned URLs, user-generated content, file management, or encountering BLOB_READ_WRITE_TOKEN errors, file size limits, client upload token errors.
What this skill does
# Vercel Blob (Object Storage) **Status**: Production Ready **Last Updated**: 2025-12-14 **Dependencies**: None **Latest Versions**: `@vercel/[email protected]` --- ## Quick Start (3 Minutes) ### 1. Create & Configure ```bash # In Vercel dashboard: Storage → Create Database → Blob vercel env pull .env.local ``` Creates: `BLOB_READ_WRITE_TOKEN` ### 2. Install ```bash bun add @vercel/blob ``` ### 3. Upload File (Server Action) ```typescript 'use server'; import { put } from '@vercel/blob'; export async function uploadFile(formData: FormData) { const file = formData.get('file') as File; const blob = await put(file.name, file, { access: 'public', contentType: file.type }); return blob.url; } ``` ### 4. Basic Operations ```typescript import { put, del, list } from '@vercel/blob'; // Upload const blob = await put('path/file.jpg', file, { access: 'public' }); // Delete await del(blob.url); // List with pagination const { blobs, cursor } = await list({ prefix: 'uploads/', limit: 100 }); ``` --- ## Critical Rules ### Always Do | Rule | Why | |------|-----| | Use client upload tokens for client-side uploads | Never expose `BLOB_READ_WRITE_TOKEN` to client | | Set `contentType` explicitly | Correct browser handling for PDFs, videos | | Use `access: 'public'` for CDN caching | Private files bypass CDN | | Validate file type and size before upload | Prevent invalid uploads | | Use pathname organization | `avatars/`, `uploads/`, `documents/` | | Delete old files when replacing | Manage storage costs | ### Never Do | Rule | Why | |------|-----| | Expose `BLOB_READ_WRITE_TOKEN` to client | Security vulnerability | | Upload files >500MB without multipart | Use `createMultipartUpload` API | | Use generic filenames | Use `${Date.now()}-${name}` or `addRandomSuffix: true` | | Skip file validation | Always validate type/size | | Store sensitive data unencrypted | Encrypt before upload | | Forget to handle pagination | `list()` returns max 1000 files | --- ## Known Issues Prevention This skill prevents **10 documented issues**: | # | Error | Quick Fix | |---|-------|-----------| | 1 | `BLOB_READ_WRITE_TOKEN not defined` | Run `vercel env pull .env.local` | | 2 | Client token exposed | Use `handleUpload()` for client uploads | | 3 | File size exceeded (500MB) | Use multipart upload API | | 4 | Wrong content-type | Set `contentType: file.type` | | 5 | No CDN caching | Use `access: 'public'` | | 6 | Missing files in list | Use cursor pagination | | 7 | Delete fails silently | Use exact URL from `put()` | | 8 | Upload timeout | Use client-side upload for large files | | 9 | Filename collisions | Add timestamp or `addRandomSuffix: true` | | 10 | State not updated | Use `onUploadCompleted` callback | **See**: `references/known-issues.md` for complete solutions with code examples. --- ## Common Patterns Summary | Pattern | Use Case | Key API | |---------|----------|---------| | **Avatar Upload** | User profile images | `put`, `del` | | **Protected Upload** | Private documents | `put` with `access: 'private'` | | **Image Gallery** | List & paginate | `list` with cursor | | **Client Upload** | Large files, progress | `upload`, `handleUpload` | | **Multipart Upload** | Files >500MB | `createMultipartUpload`, `uploadPart` | | **Batch Operations** | Multiple files | `Promise.all`, `del([...])` | | **Image Processing** | Optimize before upload | `sharp` + `put` | **See**: `references/common-patterns.md` for complete implementations. --- ## Client-Side Upload (Essential Pattern) **Server Action (Token Generation):** ```typescript 'use server'; import { handleUpload, type HandleUploadBody } from '@vercel/blob/client'; export async function generateUploadToken(body: HandleUploadBody) { return await handleUpload({ body, request: new Request('https://dummy'), onBeforeGenerateToken: async (pathname) => ({ allowedContentTypes: ['image/jpeg', 'image/png', 'image/webp'], maximumSizeInBytes: 5 * 1024 * 1024 }), onUploadCompleted: async ({ blob }) => { // Save to database await db.insert(uploads).values({ url: blob.url, pathname: blob.pathname }); } }); } ``` **Client Component:** ```typescript 'use client'; import { upload } from '@vercel/blob/client'; const blob = await upload(file.name, file, { access: 'public', handleUploadUrl: '/api/upload' }); ``` --- ## Configuration ### .env.local ```bash # Created by: vercel env pull .env.local BLOB_READ_WRITE_TOKEN="vercel_blob_rw_xxxxx" ``` ### .gitignore ``` .env.local .env*.local ``` --- ## When to Load References | Reference | Load When... | |-----------|--------------| | `references/known-issues.md` | Debugging upload errors, token issues, or CDN caching problems | | `references/common-patterns.md` | Implementing avatar uploads, galleries, client uploads, or multipart uploads | --- ## Dependencies ```json { "dependencies": { "@vercel/blob": "^2.0.0" } } ``` **Free Tier Limits**: 100GB bandwidth/month, 500MB max file size --- ## Official Documentation - **Vercel Blob**: https://vercel.com/docs/storage/vercel-blob - **Client Upload**: https://vercel.com/docs/storage/vercel-blob/client-upload - **SDK Reference**: https://vercel.com/docs/storage/vercel-blob/using-blob-sdk - **GitHub**: https://github.com/vercel/storage --- ## Troubleshooting | Problem | Solution | |---------|----------| | `BLOB_READ_WRITE_TOKEN not defined` | Run `vercel env pull .env.local` | | File size exceeded (>500MB) | Use multipart upload API | | Client upload fails | Use `handleUpload()` server-side | | Files not deleting | Use exact URL from `put()` response | --- **Token Savings**: ~60% (patterns extracted to references) **Error Prevention**: 100% (all 10 documented issues) **Ready for production!**
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.