Upstash Blob is S3-compatible object storage. @upstash/blob has a Bucket client for your server, and an upload handler plus React hooks that upload from the browser straight to storage. This page builds a working file picker on Next.js App Router. Other frameworks work the same way; see Other frameworks.
Setup#
Create a bucket in the Upstash Console and put its token in your environment.
The console asks whether the bucket is public or private:
- Public: every object has a public URL. For avatars, product images, anything a page links to directly.
- Private: no public URL. Every read goes through a time-limited signed URL. For user documents, invoices, anything that must not be guessable.
Upload from your server#
Bytes already on your server go to the bucket with put. blob.url is the public object URL, undefined on a private bucket. See Writing.
Upload from the browser#
Files a user picks go straight from the browser to storage. Your server only authorizes the upload and records the result, so the bytes never pass through it.
Write the upload handler
The handler runs on your server. It decides who may upload, where the object goes, and what happens once it lands. It never sees the bytes.
This one accepts anyone. Upload handler adds the auth check and the completion callback.
Mount it as a route
POST runs the upload and GET serves the route's constraints. The hooks look at /api/upload by default, so nothing else has to name a URL.
Bind the hooks to the handler
uploadHooks<typeof uploads>() reads the handler's type, so route names and completion data are checked at compile time. The import type is erased at build time and never pulls server code into the browser bundle.
Upload a file
You get these without more code:
- Multipart for large files. Past 16 MB the SDK switches to parts, with pause, resume and per-part retry. See Large files.
- Retries. Failed parts back off and retry, and an expired signature is refreshed mid-upload.
- A picker that matches the server.
acceptcomes from the route's ownGET, so an oversized file is refused before any request goes out. See Constraints. - Progress.
percent,statusandpendingread the same for one PUT or 200 parts. - Types end to end. Whatever
onUploadCompletereturns isupload.blob.dataon the client.