Object Storage untuk Web Developer
Object storage menyimpan file (gambar, video, backup, static assets) sebagai objek di cloud. Berbeda dari filesystem tradisional — setiap objek punya key unik, metadata, dan disimpan di bucket.
Provider Utama
- AWS S3 — Pioneer, paling mature, 99.999999999% durability
- Cloudflare R2 — S3-compatible, zero egress fees
- Google Cloud Storage (GCS) — Integrated dengan Google ecosystem
- DigitalOcean Spaces — Simple, S3-compatible
Konsep Dasar
// Bucket = container untuk objek
// Key = path/nama file dalam bucket
// Object = file + metadata
// Upload dengan AWS SDK
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const s3 = new S3Client({ region: "ap-southeast-1" });
await s3.send(new PutObjectCommand({
Bucket: "myapp-uploads",
Key: `avatars/${userId}.jpg`,
Body: fileBuffer,
ContentType: "image/jpeg",
}));
Presigned URLs
Jangan upload file melalui server — gunakan presigned URL agar client upload langsung ke S3.
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const url = await getSignedUrl(s3, new PutObjectCommand({
Bucket: "myapp-uploads",
Key: `uploads/${filename}`,
}), { expiresIn: 300 }); // 5 menit
// Client upload langsung ke URL ini
Storage Classes
- Standard — Akses sering, latency rendah
- Infrequent Access — Akses jarang, biaya storage rendah
- Glacier/Archive — Backup jangka panjang, retrieval lambat