Skip to main content

The Bucket methods, their TypeScript options and what they return. Each section links to the concept page with the behaviour and defaults.

lib/blob.ts

Building the client is on Overview. Every method runs on your server with the bucket token.


put#

lib/reports.ts

Every option is optional. Behaviour and defaults are on Writing.

OptionTypeDescription
contentTypestringWhat the object is stored as.
contentTypesstring[]An allow list such as ["image/*", "application/pdf"]. See Constraints.
maxSizeSizeRefuses a larger body with too_large.
cacheCacheOptionThe Cache-Control this object is stored with. See Caching.
metadataRecord<string, string>Custom key-value pairs. See Metadata.
sizenumberThe exact length in bytes, for a stream whose size is not otherwise known.
allowOverwritebooleanfalse refuses the write if something is already at the path. See Conditional writes.
ifUnchangedstringAn etag. The write fails with conflict if the object changed since you read it.
multipartboolean | SizeWhere a body stops being one PUT. See Large bodies.

The result is a CompletedBlob:

Bodies#

app/api/avatar/route.ts

PutBody is one of these. If the body does not carry its own length or type, declare size or contentType yourself.

BodyCarries its lengthCarries a content type
RequestFrom its content-length headerFrom its content-type header
Blob / FileYesYes, when type is set
ArrayBufferYesNo
Typed arrayYesNo
stringYes, once UTF-8 encodedNo
ReadableStream<Uint8Array>NoNo

An explicit contentType wins over what the body carries.

A Request with no body, or one that has already been read, throws empty_body. Anything else is a TypeError. A Request that arrived chunked has no content-length and counts as an unknown length, like a stream.

Streams#

A ReadableStream with neither throws length_required. Why is on Streams and unknown lengths.


uniquePath#

Exported from @upstash/blob. The suffix rules are on Unique paths.


updateJson#

OptionTypeDescription
maxAttemptsnumberHow many read-transform-write rounds to try before throwing conflict.
cacheCacheOptionThe Cache-Control the rewritten object is stored with.
metadataRecord<string, string>Replaces the metadata on the object.

The loop and its defaults are on Updating JSON.


copy and move#

OptionTypeDescription
contentTypestringWhat the destination is stored as.
cacheCacheOptionThe Cache-Control the destination is stored with.
metadataRecord<string, string>Replaces the metadata outright.

What carries over from the source is on copy and move.


signedUploadUrl#

Returns { url: string, headers: Record<string, string>, expiresAt: Date }. Send headers verbatim.

OptionTypeDescription
expiresInDurationHow long the link should live.
contentTypestringThe Content-Type the upload must send, and what the object is stored as.
cacheCacheOptionThe Cache-Control the object is stored with.
metadataRecord<string, string>Written as x-amz-meta-*, under the same rules as put.
sizeSizePins the body’s exact length.
allowOverwritebooleanfalse refuses the upload if something is already at the path.

Defaults and lifetimes are on Signed upload URLs.


get#

body is a ReadableStream<Uint8Array> and nothing is buffered for you. Wrap it in a Response for the usual conversions:

A missing object throws not_found. See get.


info and exists#

See info and exists.


list#

Returns { blobs: BlobObject[], cursor: string | undefined }.

OptionTypeDescription
prefixstringOnly keys starting with this.
limitnumberPage size.
cursorstringThe cursor from the previous page.

Defaults and paging are on list.


publicUrl#

undefined on a private bucket. An empty path, or one with a . or .. segment, throws a TypeError. See Public URLs.


signedReadUrl#

Returns { url: string, expiresAt: Date }. Cache the link until expiresAt, never until a deadline you compute from expiresIn.

OptionTypeDescription
expiresInDurationHow long to ask for.
downloadAsstringSave as this filename instead of displaying inline.
contentTypestringWhat storage answers with as Content-Type, overriding what was stored.

Defaults and lifetimes are on Signed read URLs.


del#

Anything else is refused with invalid_input. A path with a . or .. segment throws a TypeError. What each shape does and throws is on Deleting.


Multipart cleanup#

olderThan is required. See Incomplete multipart uploads.


s3#

A config for @aws-sdk/client-s3. See Using an S3 client.


Records#

Four record types come back from the SDK. They nest. What each field means is on Records.

TypeFieldsReturned by
BlobObjectpath, url?, versionedUrl?, size, etag, uploadedAtlist(), copy(), move(), updateJson()
CompletedBlobBlobObject plus contentTypeput(), onUploadComplete, a finished browser upload
BlobInfoBlobObject plus contentType and metadatainfo()
BlobDownloadBlobInfo plus body: ReadableStream<Uint8Array>get()
FieldType
pathstring
urlstring | undefined
versionedUrlstring | undefined
sizenumber
etagstring
uploadedAtDate
contentTypestring
metadataRecord<string, string>

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