Object Storage

Store and retrieve files (images, documents, etc.) using S3-compatible object storage. All objects are user-scoped.

Overview

ezAuth provides a managed file storage layer backed by any S3-compatible service (AWS S3, Backblaze B2, MinIO, etc.). Objects are organized into buckets and scoped to individual users.

Concepts

Configuration

Set the following environment variables to enable object storage:

VariableDescription
S3_ENDPOINT_URLS3-compatible endpoint (e.g., https://s3.us-west-004.backblazeb2.com)
S3_ACCESS_KEY_IDS3 access key
S3_SECRET_ACCESS_KEYS3 secret key
S3_BUCKET_NAMES3 bucket name (the actual S3 bucket, not ezAuth buckets)
S3_REGIONS3 region (default: us-east-1)
OBJECT_STORAGE_MAX_OBJECT_BYTESMax size per object (default: 50 MB)
OBJECT_STORAGE_LIMIT_BYTESTotal storage per app (default: 1 GB)

Buckets

// Create a bucket
const bucket = await ez.buckets.create({ name: 'avatars' })

// List buckets
const { buckets } = await ez.buckets.list()

// Delete a bucket
await ez.buckets.delete(bucket.id)

Uploading Objects

JavaScript (Node.js)

The JavaScript SDK doesn't include bucket object methods directly. Use the REST API:

const response = await fetch(
  `${baseUrl}/v1/buckets/${bucketId}/objects/avatar.png`,
  {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${secretKey}`,
      'Content-Type': 'image/png',
    },
    body: imageBuffer,
  }
)

Python

# Upload
ez.buckets.objects.put(
    bucket["id"],
    "avatar.png",
    image_bytes,
    "image/png",
)

# Download
data, content_type = ez.buckets.objects.get(bucket["id"], "avatar.png")

# Delete
ez.buckets.objects.delete(bucket["id"], "avatar.png")

# List objects
result = ez.buckets.objects.list(bucket["id"], limit=50)

Swift

// Upload
let obj = try await ez.buckets.objects.put(
    bucketId: bucket.id,
    key: "avatar.png",
    data: imageData,
    contentType: "image/png"
)

// Download
let (data, contentType) = try await ez.buckets.objects.get(
    bucketId: bucket.id,
    key: "avatar.png"
)

User-Scoped Access

With the secret key, specify user_id to manage objects on behalf of a user. With a publishable key + session, the user is automatically inferred from the JWT.

# Backend: access a specific user's objects
data, ct = ez.buckets.objects.get(
    bucket_id,
    "avatar.png",
    user_id="user-uuid",
)

Storage Limits

LimitDefaultConfig Variable
Max object size50 MBOBJECT_STORAGE_MAX_OBJECT_BYTES
Total storage per app1 GBOBJECT_STORAGE_LIMIT_BYTES

Check current usage:

const usage = await ez.storage.get()
// { used_bytes: 52428800, limit_bytes: 1073741824, used_percent: 4.88 }