Skip to main content

LocalStorage

@quik/storage-express


@quik/storage-express / LocalStorage

Variable: LocalStorage

const LocalStorage: object

Defined in: storage-express/src/local.ts:433

Exported helpers for working with local file storage.

Type Declaration

Decorators

Decorators: object

Helper decorators for Express route handlers.

Decorators.ArrayFile

ArrayFile: (fieldName, maxCount?) => <This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Accept multiple file uploads for a field and expose them on the request context.

Parameters
fieldName

string

maxCount?

number

Returns

<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Decorators.ArrayFilePersist

ArrayFilePersist: (fieldName, maxCount?, destination?) => <This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Accept multiple files and persist them to storage.

Parameters
fieldName

string

Multer field name.

maxCount?

number

Max number of files to accept.

destination?

string

Destination folder or file path.

Returns

<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Decorators.NoUploads

NoUploads: () => <This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Reject all file uploads for the route.

Returns

<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Decorators.RequireSignedToken

RequireSignedToken: (purpose) => <This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return> = RequireLocalStorageToken

Verify a signed local storage token before the handler runs; throws when missing, invalid, expired, or issued for a different purpose.

Endpoint middleware decorator that verifies a signed local storage token before the handler runs.

Expects the endpoint's query parameters to include a token field carrying a token produced by LocalSignature.sign/QLocalStorageEngine.getSignedUploadURL/getSignedDownloadURL. Throws StorageInvalidSignedURLError, StorageSignedURLExpiredError, or StorageSignedURLPurposeMismatchError when the token is missing, malformed, expired, or was issued for a different purpose; otherwise execution continues and the verified storage path is made available to the handler via event.getObject(LOCAL_STORAGE_TOKEN_PATH_KEY).

Parameters
purpose

QLocalSignaturePurpose

Purpose the token must have been issued for.

Returns

<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Throws

StorageInvalidSignedURLError When the token query parameter is missing or malformed.

Throws

StorageSignedURLPurposeMismatchError When the token was issued for a different purpose.

Example
@Decorators.Endpoint.GET("/download", { query: LocalStorageTokenQuery })
@RequireLocalStorageToken("download")
public async download(event: QQueryParametersOnlyEvent<LocalStorageTokenQuery>): Promise<IQResponse> {
const path = event.getObject<string>(LOCAL_STORAGE_TOKEN_PATH_KEY);
// ...
}
Param

purpose

Purpose the token must have been issued for.

Decorators.SingleFile

SingleFile: (fieldName) => <This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Accept a single file upload and expose it on the request context.

Parameters
fieldName

string

Returns

<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Decorators.SingleFilePersist

SingleFilePersist: (fieldName, destination?) => <This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

Accept a single file upload and persist it to storage.

Parameters
fieldName

string

Multer field name.

destination?

string

Destination folder or file path.

Returns

<This, Args, Return>(target, context) => MethodDecoratorType<This, Args, Return>

init

init: () => void

Initialise the Multer middleware and register entities if local storage is enabled.

Returns

void