Skip to content

Flect store

Part of the flect skill set.

Flect object stores are S3-compatible, powered by Garage. Each store is its own bucket with its own API key pair. env.store(binding) returns an official @aws-sdk/client-s3 S3Client, pre-configured with the endpoint, region, and credentials.

Terminal window
flect store create my-uploads
flect store list
flect store status <ref>
flect store delete <ref>
[[stores]]
binding = "FILES"
name = "my-uploads"
import { createEnv } from '@getflect/sdk'
import { PutObjectCommand, GetObjectCommand, DeleteObjectCommand } from '@aws-sdk/client-s3'
const env = createEnv()
const s3 = await env.store('FILES') // configured S3Client
const Bucket = process.env.FILES_BUCKET! // the resolved bucket name (<BINDING>_BUCKET)
await s3.send(new PutObjectCommand({ Bucket, Key: 'hello.txt', Body: 'Hello, Flect!', ContentType: 'text/plain' }))
const { Body } = await s3.send(new GetObjectCommand({ Bucket, Key: 'hello.txt' }))
const text = await Body?.transformToString()
await s3.send(new DeleteObjectCommand({ Bucket, Key: 'hello.txt' }))

The bucket name is not the binding — read it from process.env.<BINDING>_BUCKET. It’s the real S3Client, so use official commands, not store.put().

Presigned URLs (direct browser upload/download)

Section titled “Presigned URLs (direct browser upload/download)”
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
import { PutObjectCommand } from '@aws-sdk/client-s3'
const url = await getSignedUrl(
s3,
new PutObjectCommand({ Bucket, Key: `uploads/${filename}`, ContentType: type }),
{ expiresIn: 300 },
)

Each store has its own Garage API key, scoped to its own bucket — a key for store A cannot touch store B. Garage requires path-style addressing, which the resolved client already sets (forcePathStyle: true).

Terminal window
flect dev # createEnv() resolves the store locally
docker run -d -p 9000:9000 -p 9001:9001 \
-e MINIO_ROOT_USER=minioadmin -e MINIO_ROOT_PASSWORD=minioadmin \
quay.io/minio/minio server /data --console-address ":9001"

Set S3_ENDPOINT, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY (see Local development) and create the bucket in the MinIO console at http://localhost:9001.