Blob
Store, list, read, serve, and delete files from Vite and Nitro server code with one provider-neutral Blob API.
@vitehub/blob gives Vite and Nitro apps one server-side Blob API for local files, Cloudflare R2, and Vercel Blob.
Use Blob when routes need to accept user files, write generated assets, list stored objects, or stream a stored file back through the application.
import { createError, defineEventHandler, readFormData } from 'h3'
import { blob, ensureBlob } from '@vitehub/blob'
export default defineEventHandler(async (event) => {
const form = await readFormData(event)
const file = form.get('file')
if (!(file instanceof Blob)) {
throw createError({ statusCode: 400, statusMessage: 'Expected a file upload.' })
}
ensureBlob(file, { maxSize: '1MB', types: ['image'] })
return await blob.put('avatar.png', file, {
addRandomSuffix: true,
prefix: 'avatars',
})
})
{
"pathname": "avatars/avatar-a1b2c3d4.png",
"contentType": "image/png",
"size": 8421,
"httpEtag": "\"6f1d...\"",
"uploadedAt": "2026-04-26T12:00:00.000Z",
"httpMetadata": {
"contentType": "image/png"
},
"customMetadata": {}
}
What Blob Solves
Object storage APIs differ by platform. Blob keeps route code focused on pathnames, bodies, metadata, and streams while the active driver handles provider details.
Portable writes
Store strings,
Blobs, ArrayBuffers, typed arrays, or streams with the same blob.put() call.Listings and metadata
Page through objects with
prefix, limit, cursor, and folded folder-style listings.Route streaming
Serve stored files from H3 routes with content headers set by
blob.serve().Upload checks
Reject files by MIME type or size before they reach storage with
ensureBlob().One Portable Flow
The same shape works across supported runtimes:
- Install
@vitehub/blob. - Register
hubBlob()for Vite or@vitehub/blob/nitrofor Nitro. - Choose a storage driver or let hosting inference pick one.
- Use
blob.put(),blob.list(),blob.get(),blob.head(),blob.del(), andblob.serve()from server routes. - Move provider-specific tokens, bindings, and bucket names into config or environment.
Blob is a server-side API. Import
blob from server routes, handlers, or build-generated server entries, not from browser code.Storage Resolution
ViteHub resolves Blob storage in this order:
- Explicit
blob.driverconfig wins. - Cloudflare hosting resolves
cloudflare-r2. BLOB_READ_WRITE_TOKENresolvesvercel-blob.- Vercel hosting resolves
vercel-blob. - Everything else falls back to
fsat.data/blob.
Supported Storage Paths
Start Here
Start with Quickstart for a local fs setup. Use the primitive comparison when you are choosing between Blob, KV, Queue, Sandbox, and inline response data.

