File Storage S3 Overview
The file-storage-s3 package provides an S3-compatible backend for the FileStorage interface. It lets you store and retrieve File objects using Amazon S3, Cloudflare R2, MinIO, or any service that speaks the S3 API.
Because it implements the same FileStorage interface as the filesystem and memory backends, you can swap to S3 storage without changing any application code that reads or writes files.
Quick Example
ts
import { createS3FileStorage } from 'remix/file-storage-s3'
let storage = createS3FileStorage({
bucket: 'my-app-uploads',
region: 'us-east-1',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
},
})
// Store a file
let file = new File(['hello'], 'greeting.txt', { type: 'text/plain' })
await storage.set('docs/greeting.txt', file)
// Retrieve it
let retrieved = await storage.get('docs/greeting.txt')
console.log(await retrieved?.text()) // 'hello'Key Concepts
- Bucket -- An S3 bucket is a top-level container for objects. You specify it when creating the storage backend.
- Region -- The AWS region where the bucket is hosted (e.g.,
us-east-1). For non-AWS services like R2, check the provider's documentation. - Credentials -- Access key and secret key for authentication. If omitted, the SDK uses the default credential chain (environment variables, IAM roles, etc.).
- Endpoint -- A custom URL for S3-compatible services like Cloudflare R2 or MinIO.
- Prefix -- A string prepended to all keys, useful for organizing files within a single bucket.
Compatible Services
| Service | Configuration |
|---|---|
| Amazon S3 | Set bucket and region |
| Cloudflare R2 | Set endpoint to your R2 URL, region to auto |
| MinIO | Set endpoint to your MinIO URL, enable forcePathStyle |
| DigitalOcean Spaces | Set endpoint to your Spaces URL |
Related
- file-storage -- The base interface and other backends
- form-data-parser -- Parse uploads and stream to S3
- API Reference -- Full API documentation