Skip to main content

@upstash/blob is the TypeScript SDK. It has a Bucket client and an upload handler for your server, and the browser client that uploads from the browser straight to storage.

This section is the TypeScript reference: names, types, and framework wiring. What each call does, its defaults and its limits are on the concept pages it links to.


Install#

The package bundles these docs at node_modules/@upstash/blob/docs/.


Entrypoints#

ImportRuns onExports
@upstash/blobyour serverBucket, uploadHandler, uploadRoute, uniquePath, BlobError, formatBytes, and the types
@upstash/blob/browserthe browserupload, BlobError, formatBytes
@upstash/blob/reactthe browseruploadHooks, useUpload, useServerUpload, BlobError, formatBytes

/browser and /react are the browser client. They talk to an upload route over HTTP, so the route behind them can be written with any server SDK.


The Bucket client#

lib/blob.ts
lib/blob.ts

Bucket.fromEnv() is the same constructor with token read from UPSTASH_BLOB_TOKEN. It takes the same options minus the token, and a variable name when the token lives somewhere else:

OptionTypeDescription
tokenstringRequired. The bucket token. See Connecting.
cacheCacheOptionThe default Cache-Control for every object this client stores. A per-call cache overrides it. See Caching.
enableTelemetrybooleanfalse turns telemetry off for this client. See Telemetry.
retryRetryConfigfalse, or { retries, backoff }. See Retries.

There is no visibility option. Whether the bucket is public or private is a console setting; see Connecting.

Cloudflare Workers#

There is no process.env on Workers, so Bucket.fromEnv() throws. Pass the token from the request’s env:

src/index.ts

An upload handler on Workers needs the same thing: build the bucket from env and pass it as bucket:.

Retries#

FieldTypeDescription
retriesnumberRetries after the first attempt, for every request this client makes.
backoff(retryCount: number) => numberMilliseconds before retry retryCount, counted from 0. A Retry-After from the service wins over it.

Which requests are retried, and the default budget and backoff, are on Retries.


Using an S3 client#

bucket.s3() returns a config for @aws-sdk/client-s3. endpoint and credentials are async providers rather than values. Pass them through as they come, so the aws-sdk can pick up a fresh credential when the old one expires.

What an S3 client is for, and why it must not presign, is on Using an S3 client.


Option types#

TypeTypeScriptGrammar
Sizenumber | stringSize
Durationnumber | stringDuration
CacheOptionDuration | 'immutable' | 'revalidate' | 'no-store'CacheOption. A raw header is a string.

All three are exported as types from @upstash/blob.

A limit you write by hand takes a Size: maxSize, multipart. A measurement you forward is a plain number of bytes: the size option on put, and every size the SDK returns. That mirrors File.size and Blob.size, so a value flows from one to the other without conversion.


Next steps#