⚠️ Moved to Codeberg: https://codeberg.org/thinking_tools/s3mini - Tiny S3 client. Edge computing ready. No-dep. In Typescript.
⚠️ Moved to Codeberg: https://codeberg.org/thinking_tools/s3mini - Tiny S3 client. Edge computing ready. No-dep. In Typescript.
s3mini is an ultra-lightweight Typescript client (~20 KB minified, ≈15 % more ops/s) for S3-compatible object storage. It runs on Node, Bun, Cloudflare Workers, and other edge platforms. It has been tested on Cloudflare R2, Backblaze B2, DigitalOcean Spaces, Ceph, Oracle, Garage and MinIO. (No Browser support!)
[code.nolog] [issues] [npm]
and more ... Contributions welcome!
s3mini is tested on both Node and Bun. In our benchmarks against MinIO, Bun is roughly ~1.4x faster on most operations (median across ~40 tests). Blob multipart uploads see the largest gain (~20x) thanks to Bun's native Blob.slice(). Results are approximate and will vary by environment.
npm install s3miniyarn add s3minipnpm add s3miniTo use s3mini, you need to set up your environment variables for provider credentials and S3 endpoint. Create a .env file in your project root directory. Checkout the example.env file for reference.
# On Windows, Mac, or Linux
mv example.env .env⚠️ Environment Support Notice
This library is designed to run in environments like Node.js, Bun, and Cloudflare Workers. It does not support browser environments due to the use of Node.js APIs and polyfills.
import { S3mini } from 's3mini';
const s3 = new S3mini({
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
endpoint: 'https://bucket.region.r2.cloudflarestorage.com',
region: 'auto',
});
// Upload (auto-selects single PUT or multipart based on size)
await s3.putAnyObject('photos/vacation.jpg', fileBuffer, 'image/jpeg');
// Download
const data = await s3.getObject('photos/vacation.jpg');
// List
const objects = await s3.listObjects('/', 'photos/');
// Delete
await s3.deleteObject('photos/vacation.jpg');const s3 = new S3mini({
// Required
accessKeyId: string,
secretAccessKey: string,
endpoint: string, // Full URL: https://bucket.region.provider.com
// Optional
region: string, // Default: 'auto'
minPartSize: number, // Default: 8MB — threshold for multipart
requestSizeInBytes: number, // Default: 8MB — chunk size for range requests
requestAbortTimeout: number, // Timeout in ms (undefined = no timeout)
logger: Logger, // Custom logger with info/warn/error methods
fetch: typeof fetch, // Custom fetch implementation
});Endpoint formats:
// Path-style (bucket in path)
'https://s3.us-east-1.amazonaws.com/my-bucket';
// Virtual-hosted-style (bucket in subdomain)
'https://my-bucket.s3.us-east-1.amazonaws.com';
// Provider-specific
'https://my-bucket.nyc3.digitaloceanspaces.com';
'https://account-id.r2.cloudflarestorage.com/my-bucket';Direct single-request upload. Use for small files or when you need fine control.
const response = await s3.putObject(
key: string, // Object key/path
data: string | Buffer | Uint8Array | Blob | File | ReadableStream,
contentType?: string, // Default: 'application/octet-stream'
ssecHeaders?: SSECHeaders, // Optional encryption headers
additionalHeaders?: AWSHeaders, // Optional x-amz-* headers
contentLength?: number, // Optional, auto-detected for most types
);
// Returns: Response object
const etag = response.headers.get('etag');Examples:
// String content
await s3.putObject('config.json', JSON.stringify({ key: 'value' }), 'application/json');
// Buffer/Uint8Array
const buffer = await fs.readFile('image.png');
await s3.putObject('images/photo.png', buffer, 'image/png');
// Blob (browser File API or Node 18+)
const blob = new Blob(['Hello'], { type: 'text/plain' });
await s3.putObject('hello.txt', blob, 'text/plain');
// With custom headers
await s3.putObject('data.bin', buffer, 'application/octet-stream', undefined, {
'x-amz-meta-author': 'john',
'x-amz-meta-version': '1.0',
});Automatically chooses single PUT or multipart based on data size. This is the recommended method for most use cases.
const response = await s3.putAnyObject(
key: string,
data: string | Buffer | Uint8Array | Blob | File | ReadableStream,
contentType?: string,
ssecHeaders?: SSECHeaders,
additionalHeaders?: AWSHeaders,
contentLength?: number,
);Behavior:
Examples:
…Memory efficiency with Blobs:
For large files, using Blob or File is more memory-efficient than Uint8Array:
// ❌ Loads entire file into memory
const buffer = await fs.readFile('large-video.mp4');
await s3.putAnyObject('video.mp4', buffer);
// ✅ Zero-copy slicing — only reads data when uploading each part
const file = Bun.file('large-video.mp4'); // Bun
// or
const blob = await fs.openAsBlob('large-video.mp4'); // Node
await s3.putAnyObject('video.mp4', blob);For advanced control over multipart uploads (progress tracking, resumable uploads, custom concurrency).
…Parallel uploads with progress:
…Abort an incomplete upload:
await s3.abortMultipartUpload(key, uploadId);List pending multipart uploads:
const pending = await s3.listMultipartUploads();
// Clean up orphaned uploads
for (const upload of pending.Upload || []) {
await s3.abortMultipartUpload(upload.Key, upload.UploadId);
}…// List all objects (auto-paginates)
const objects = await s3.listObjects();
// With prefix filter (list "folder")
const photos = await s3.listObjects('/', 'photos/');
// With max keys limit
const first100 = await s3.listObjects('/', '', 100);
// Manual pagination
let token: string | undefined;
do {
const { objects, nextContinuationToken } = await s3.listObjectsPaged(
'/', // delimiter
'uploads/', // prefix
100, // maxKeys per page
token, // continuation token
);
console.log(objects);
token = nextContinuationToken;
} while (token);Response shape:
interface ListObject {
Key: string;
Size: number;
LastModified: Date;
ETag: string;
StorageClass: string;
}// Single object
const deleted = await s3.deleteObject('file.txt'); // boolean
// Multiple objects (batched, max 1000 per request)
const keys = ['a.txt', 'b.txt', 'c.txt'];
const results = await s3.deleteObjects(keys); // boolean[] in same orderServer-side copy (no data transfer through client):
// Copy within same bucket
const result = await s3.copyObject('source.txt', 'backup/source.txt');
// Copy with new metadata
await s3.copyObject('report.pdf', 'archive/report.pdf', {
metadataDirective: 'REPLACE',
metadata: {
'archived-at': new Date().toISOString(),
},
contentType: 'application/pdf',
});
// Move (copy + delete source)
await s3.moveObject('temp/upload.tmp', 'files/document.pdf');Options:
interface CopyObjectOptions {
metadataDirective?: 'COPY' | 'REPLACE';
metadata?: Record;
contentType?: string;
storageClass?: string;
taggingDirective?: 'COPY' | 'REPLACE';
sourceSSECHeaders?: SSECHeaders;
destinationSSECHeaders?: SSECHeaders;
additionalHeaders?: AWSHeaders;
}Use If-* headers to avoid unnecessary transfers:
// Only download if changed (returns null if ETag matches)
const data = await s3.getObject('file.txt', {
'if-none-match': '"abc123"',
});
// Only download if modified since date
const data = await s3.getObject('file.txt', {
'if-modified-since': 'Wed, 21 Oct 2024 07:28:00 GMT',
});
// Check existence with conditions
const exists = await s3.objectExists('file.txt', {
'if-match': '"abc123"',
}); // null if ETag mismatch, true/false otherwiseGenerate time-limited URLs that allow unauthenticated HTTP clients to upload or download objects directly — no credentials needed on the client side.
// Download URL (valid for 1 hour by default)
const downloadUrl = await s3.getPresignedUrl('GET', 'photos/vacation.jpg');
// Upload URL (valid for 5 minutes)
const uploadUrl = await s3.getPresignedUrl('PUT', 'uploads/file.bin', 300);Client-side usage (no SDK or credentials required):
// Upload via pre-signed URL
await fetch(uploadUrl, {
method: 'PUT',
body: fileData,
headers: { 'Content-Type': 'image/jpeg' },
});
// Download via pre-signed URL
const response = await fetch(downloadUrl);
const data = await response.arrayBuffer();Custom response headers:
// Force download with a specific filename
const url = await s3.getPresignedUrl('GET', 'report.pdf', 3600, {
'response-content-disposition': 'attachment; filename="report.pdf"',
'response-content-type': 'application/pdf',
});Signed headers (enforce headers on the client request):
// Upload URL that requires Content-Type — client MUST send this exact header
const url = await s3.getPresignedUrl(
'PUT',
'uploads/data.json',
300,
{},
{
'Content-Type': 'application/json',
},
);
await fetch(url, {
method: 'PUT',
body: JSON.stringify({ ok: true }),
headers: { 'Content-Type': 'application/json' },
});Method signature:
getPresignedUrl(
method: 'GET' | 'PUT',
key: string,
expiresIn?: number, // Default: 3600 (1 hour), max: 604800 (7 days)
queryParams?: Record<string, string>,
headers?: Record<string, string>, // HTTP headNo open issues yet, or sync has not completed.