Appearance
S3 Storage Provider
The S3 Storage Provider is a decoupled implementation of the IStorageProvider port that allows the application to interact with Amazon S3 or any S3-compatible service (like MinIO or DigitalOcean Spaces).
Interface: IStorageProvider
The interface defines the following operations:
upload(params): Direct server-side upload.download(key): Retrieve file content as a Buffer.delete(key): Remove an object from storage.exists(key): Check for object existence usingHeadObject.getReadUrl(params): Generate a presigned GET URL.getUploadUrl(params): Generate a presigned PUT URL.
Configuration
The provider is configured via environment variables:
AWS_REGION: The AWS region (e.g.,us-east-1).AWS_ACCESS_KEY_ID: Your S3 access key.AWS_SECRET_ACCESS_KEY: Your S3 secret key.STORAGE_PUBLIC_S3_BUCKET_NAME: Bucket for publicly accessible files.STORAGE_PRIVATE_S3_BUCKET_NAME: Bucket for private/protected files.STORAGE_S3_ENDPOINT: (Optional) Custom endpoint for S3-compatible services.
Usage
Inject the provider using the StorageProviderKey:
typescript
constructor(
@Inject(StorageProviderKey)
private readonly storageProvider: IStorageProvider
) {}
async someMethod() {
const result = await this.storageProvider.upload({
key: 'path/to/file.txt',
body: Buffer.from('content'),
contentType: 'text/plain'
});
}S3-Compatible Services
To use a service like MinIO, set the STORAGE_S3_ENDPOINT environment variable:
env
STORAGE_S3_ENDPOINT=http://localhost:9000When an endpoint is provided, the adapter automatically enables forcePathStyle, which is typically required for local MinIO setups.