Back to Encore

encore.dev/storage/objects

docs/ts/runtime/storage-objects.mdx

1.57.519.5 KB
Original Source

Classes

<!-- symbol-start: Bucket -->

Bucket <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L27" />

Defines a new Object Storage bucket infrastructure resource.

Extends

Implements

Constructors

Constructor <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L34" />

new Bucket(name, cfg?): Bucket

Creates a new bucket with the given name and configuration

Parameters
name

string

cfg?

BucketConfig

Returns

Bucket

Overrides

BucketPerms.constructor

Properties

impl

impl: Bucket

Methods

attrs() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L75" />

attrs(name, options?): Promise<ObjectAttrs>

Returns the object's attributes. Throws an error if the object does not exist.

Parameters
name

string

options?

AttrsOptions

Returns

Promise<ObjectAttrs>

Implementation of

Attrser.attrs

download() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L121" />

download(name, options?): Promise<Buffer>

Downloads an object from the bucket and returns its contents.

Parameters
name

string

options?

DownloadOptions

Returns

Promise<Buffer>

Implementation of

Downloader.download

exists() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L64" />

exists(name, options?): Promise<boolean>

Returns whether the object exists in the bucket. Throws an error on network failure.

Parameters
name

string

options?

ExistsOptions

Returns

Promise<boolean>

Implementation of

Attrser.exists

list() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L47" />

list(options): AsyncGenerator<ListEntry>

Parameters
options

ListOptions

Returns

AsyncGenerator<ListEntry>

Implementation of

Lister.list

publicUrl() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L145" />

publicUrl(name): string

Returns the public URL for accessing the object with the given name. Throws an error if the bucket is not public.

Parameters
name

string

Returns

string

Implementation of

PublicUrler.publicUrl

ref() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L150" />

ref<P>(): P

Type Parameters
P

P extends BucketPerms

Returns

P

remove() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L132" />

remove(name, options?): Promise<void>

Removes an object from the bucket. Throws an error on network failure.

Parameters
name

string

options?

DeleteOptions

Returns

Promise<void>

Implementation of

Remover.remove

signedDownloadUrl() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L111" />

signedDownloadUrl(name, options?): Promise<SignedDownloadUrl>

Generate an external URL to allow downloading an object from the bucket.

Anyone with possession of the URL can download the given object without any additional auth.

Parameters
name

string

options?

DownloadUrlOptions

Returns

Promise<SignedDownloadUrl>

Implementation of

SignedDownloader.signedDownloadUrl

signedUploadUrl() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L98" />

signedUploadUrl(name, options?): Promise<SignedUploadUrl>

Generate an external URL to allow uploading an object to the bucket.

Anyone with possession of the URL can write to the given object name without any additional auth.

Parameters
name

string

options?

UploadUrlOptions

Returns

Promise<SignedUploadUrl>

Implementation of

SignedUploader.signedUploadUrl

upload() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L85" />
ts
upload(
   name, 
   data, 
options?): Promise<ObjectAttrs>;

Uploads an object to the bucket.

Parameters
name

string

data

Buffer

options?

UploadOptions

Returns

Promise<ObjectAttrs>

Implementation of

Uploader.upload

named() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L43" />

static named<name>(name): Bucket

Reference an existing bucket by name. To create a new storage bucket, use new StorageBucket(...) instead.

Type Parameters
name

name extends string

Parameters
name

StringLiteral<name>

Returns

Bucket


<!-- symbol-end --> <!-- symbol-start: ObjectNotFound -->

ObjectNotFound <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/error.ts#L22" />

Extends

Constructors

Constructor <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/error.ts#L23" />

new ObjectNotFound(msg): ObjectNotFound

Parameters
msg

string

Returns

ObjectNotFound

Overrides

ObjectsError.constructor


<!-- symbol-end --> <!-- symbol-start: ObjectsError -->

ObjectsError <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/error.ts#L3" />

Extends

  • Error

Extended by

Constructors

Constructor <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/error.ts#L4" />

new ObjectsError(msg): ObjectsError

Parameters
msg

string

Returns

ObjectsError

Overrides

Error.constructor


<!-- symbol-end --> <!-- symbol-start: PreconditionFailed -->

PreconditionFailed <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/error.ts#L41" />

Extends

Constructors

Constructor <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/error.ts#L42" />

new PreconditionFailed(msg): PreconditionFailed

Parameters
msg

string

Returns

PreconditionFailed

Overrides

ObjectsError.constructor

<!-- symbol-end -->

Interfaces

<!-- symbol-start: Attrser -->

Attrser <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L24" />

Extends

Methods

attrs() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L25" />

abstract attrs(name, options?): Promise<ObjectAttrs>

Parameters
name

string

options?

AttrsOptions

Returns

Promise<ObjectAttrs>

exists() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L26" />

abstract exists(name, options?): Promise<boolean>

Parameters
name

string

options?

ExistsOptions

Returns

Promise<boolean>


<!-- symbol-end --> <!-- symbol-start: AttrsOptions -->

AttrsOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L172" />

Options for retrieving the attributes of an object.

Properties

version?

optional version?: string

The object version to retrieve attributes for. Defaults to the lastest version if unset.

If bucket versioning is not enabled, this option is ignored.


<!-- symbol-end --> <!-- symbol-start: BucketConfig -->

BucketConfig <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L10" />

Configuration options for declaring a Bucket.

Properties

public?

optional public?: boolean

Whether the objects in the bucket should be publicly accessible, via CDN. Defaults to false if unset.

versioned?

optional versioned?: boolean

Whether to enable versioning of the objects in the bucket. Defaults to false if unset.


<!-- symbol-end --> <!-- symbol-start: BucketPerms -->

BucketPerms <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L4" />

Extended by


<!-- symbol-end --> <!-- symbol-start: DeleteOptions -->

DeleteOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L198" />

Options for deleting an object from a bucket.

Properties

version?

optional version?: string

The object version to delete. Defaults to the lastest version if unset.

If bucket versioning is not enabled, this option is ignored.


<!-- symbol-end --> <!-- symbol-start: Downloader -->

Downloader <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L16" />

Extends

Methods

download() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L17" />

abstract download(name, options?): Promise<Buffer>

Parameters
name

string

options?

DownloadOptions

Returns

Promise<Buffer>


<!-- symbol-end --> <!-- symbol-start: DownloadOptions -->

DownloadOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L211" />

Options for downloading an object from a bucket.

Properties

version?

optional version?: string

The object version to download. Defaults to the lastest version if unset.

If bucket versioning is not enabled, this option is ignored.


<!-- symbol-end --> <!-- symbol-start: DownloadUrlOptions -->

DownloadUrlOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L272" />

Options for generating a signed download URL.

Properties

ttl?

optional ttl?: number

The expiration time of the url, in seconds from signing. The maximum value is seven days. If no value is given, a default of one hour is used.


<!-- symbol-end --> <!-- symbol-start: ExistsOptions -->

ExistsOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L185" />

Options for checking the existence of an object.

Properties

version?

optional version?: string

The object version to check for existence. Defaults to the lastest version if unset.

If bucket versioning is not enabled, this option is ignored.


<!-- symbol-end --> <!-- symbol-start: ListEntry -->

ListEntry <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L236" />

A single entry returned when listing objects in a bucket.

Properties

etag

etag: string

name

name: string

size

size: number


<!-- symbol-end --> <!-- symbol-start: Lister -->

Lister <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L29" />

Extends

Methods

list() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L30" />

abstract list(options): AsyncGenerator<ListEntry>

Parameters
options

ListOptions

Returns

AsyncGenerator<ListEntry>


<!-- symbol-end --> <!-- symbol-start: ListOptions -->

ListOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L158" />

Options for listing objects in a bucket.

Properties

limit?

optional limit?: number

Maximum number of objects to return. Defaults to no limit.

prefix?

optional prefix?: string

Only include objects with this prefix in the listing. If unset, all objects are included.


<!-- symbol-end --> <!-- symbol-start: ObjectAttrs -->

ObjectAttrs <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L224" />

Describes the attributes of an object stored in a bucket.

Properties

contentType?

optional contentType?: string

etag

etag: string

name

name: string

size

size: number

version?

optional version?: string

The version of the object, if bucket versioning is enabled.


<!-- symbol-end --> <!-- symbol-start: PublicUrler -->

PublicUrler <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L37" />

Extends

Methods

publicUrl() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L38" />

abstract publicUrl(name): string

Parameters
name

string

Returns

string


<!-- symbol-end --> <!-- symbol-start: Remover -->

Remover <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L33" />

Extends

Methods

remove() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L34" />

abstract remove(name, options?): Promise<void>

Parameters
name

string

options?

DeleteOptions

Returns

Promise<void>


<!-- symbol-end --> <!-- symbol-start: SignedDownloader -->

SignedDownloader <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L20" />

Extends

Methods

signedDownloadUrl() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L21" />

abstract signedDownloadUrl(name, options?): Promise<SignedDownloadUrl>

Parameters
name

string

options?

DownloadUrlOptions

Returns

Promise<SignedDownloadUrl>


<!-- symbol-end --> <!-- symbol-start: SignedDownloadUrl -->

SignedDownloadUrl <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L282" />

A signed URL that allows downloading an object without additional auth.

Properties

url

url: string


<!-- symbol-end --> <!-- symbol-start: SignedUploader -->

SignedUploader <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L12" />

Extends

Methods

signedUploadUrl() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L13" />

abstract signedUploadUrl(name, options?): Promise<SignedUploadUrl>

Parameters
name

string

options?

UploadUrlOptions

Returns

Promise<SignedUploadUrl>


<!-- symbol-end --> <!-- symbol-start: SignedUploadUrl -->

SignedUploadUrl <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L265" />

A signed URL that allows uploading an object without additional auth.

Properties

url

url: string


<!-- symbol-end --> <!-- symbol-start: Uploader -->

Uploader <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L8" />

Extends

Methods

upload() <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L9" />
ts
abstract upload(
   name, 
   data, 
options?): Promise<ObjectAttrs>;
Parameters
name

string

data

Buffer

options?

UploadOptions

Returns

Promise<ObjectAttrs>


<!-- symbol-end --> <!-- symbol-start: UploadOptions -->

UploadOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L245" />

Options for uploading an object to a bucket.

Properties

contentType?

optional contentType?: string

preconditions?
ts
optional preconditions?: {
  notExists?: boolean;
};
notExists?

optional notExists?: boolean


<!-- symbol-end --> <!-- symbol-start: UploadUrlOptions -->

UploadUrlOptions <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/bucket.ts#L255" />

Options for generating a signed upload URL.

Properties

ttl?

optional ttl?: number

The expiration time of the url, in seconds from signing. The maximum value is seven days. If no value is given, a default of one hour is used.

<!-- symbol-end -->

Type Aliases

<!-- symbol-start: ReadWriter -->

ReadWriter <SymbolSource href="https://github.com/encoredev/encore/blob/main/runtimes/js/encore.dev/storage/objects/refs.ts#L41" />

type ReadWriter = Uploader & SignedUploader & Downloader & SignedDownloader & Attrser & Lister & Remover

<!-- symbol-end -->