Skip to main content

S3AssetStorageStrategy

An AssetStorageStrategy which uses Amazon S3 object storage service. To us this strategy you must first have access to an AWS account. See their getting started guide for how to get set up.

Before using this strategy, make sure you have the @aws-sdk/client-s3 and @aws-sdk/lib-storage package installed:

Note: Rather than instantiating this manually, use the configureS3AssetStorage function.

Use with S3-compatible services (MinIO)

This strategy will also work with any S3-compatible object storage solutions, such as MinIO. See the configureS3AssetStorage for an example with MinIO.

Signature

constructor

method(s3Config: S3Config, toAbsoluteUrl: (request: Request, identifier: string) => string) => S3AssetStorageStrategy

init

method() =>

destroy

property(() => void | Promise<void>) | undefined

writeFileFromBuffer

method(fileName: string, data: Buffer) =>

writeFileFromStream

method(fileName: string, data: Readable) =>

readFileToBuffer

method(identifier: string) =>

readFileToStream

method(identifier: string) =>

deleteFile

method(identifier: string) =>

fileExists

method(fileName: string) =>

Configuration for connecting to AWS S3.

Signature

credentials

propertyAwsCredentialIdentity | AwsCredentialIdentityProvider

The credentials used to access your s3 account. You can supply either the access key ID & secret, or you can make use of a shared credentials file To use a shared credentials file, import the fromIni() function from the "@aws-sdk/credential-provider-ini" or "@aws-sdk/credential-providers" package and supply the profile name (e.g. { profile: 'default' }) as its argument.

bucket

propertystring

The S3 bucket in which to store the assets. If it does not exist, it will be created on startup.

nativeS3Configuration

propertyany

Configuration object passed directly to the AWS SDK. S3.Types.ClientConfiguration can be used after importing aws-sdk. Using type any in order to avoid the need to include aws-sdk dependency in general.

nativeS3UploadConfiguration

propertyany

Configuration object passed directly to the AWS SDK. ManagedUpload.ManagedUploadOptions can be used after importing aws-sdk. Using type any in order to avoid the need to include aws-sdk dependency in general.

Returns a configured instance of the S3AssetStorageStrategy which can then be passed to the AssetServerOptionsstorageStrategyFactory property.

Before using this strategy, make sure you have the @aws-sdk/client-s3 and @aws-sdk/lib-storage package installed:

Example

Ts

Usage with MinIO

Reference: How to use AWS SDK for Javascript with MinIO Server

Example

Ts
Signature

Parameters

s3Config

parameterS3Config
Was this chapter helpful?
Report Issue
Edited Feb 23, 2026ยทEdit this page