EPUB Upload & Storage
15 min read
Configure S3-Compatible Storage
Configure S3-Compatible Storage
Task
Add one S3 client boundary so the rest of the application does not know whether storage is SeaweedFS, another S3-compatible service, or a production object store.
Install
npm install @aws-sdk/client-s3
File
Create:
lib/storage.ts
Implementation
import { S3Client } from "@aws-sdk/client-s3";
export const storage = new S3Client({
endpoint: process.env.S3_ENDPOINT,
region: process.env.S3_REGION ?? "us-east-1",
forcePathStyle: true,
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY!,
secretAccessKey: process.env.S3_SECRET_KEY!,
},
});
export const bucket = process.env.S3_BUCKET!;
Keep credentials server-side.
Test
Start the application with the storage environment configured. Import the storage client from a server-side module without creating a browser bundle dependency.
Checkpoint
Readly has a single S3-compatible storage boundary that can target local SeaweedFS and later production storage.