A small service that handles image uploads for an imaginary chat application: it stores encrypted files, creates a resized original + a preview image, and records upload metadata for later retrieval.
Inspired by Code Aesthetic’s “file upload service” walkthrough (the video uses TypeScript; this project is the Go implementation).
- Upload images over HTTP
- Resize originals (max width) + generate preview images
- Encrypt stored files (AES-GCM)
- Record metadata in SQLite for later downloads
- Support for local filesystem or S3-compatible storage backends
- Go 1.21+
- A C toolchain (required by
github.com/mattn/go-sqlite3)
make serverThe server listens on http://localhost:1323 and writes:
- Metadata:
filer.sqlite - Encrypted files:
temp/<upload-uuid>/...(local storage) or S3 bucket (S3 storage) - Working files:
vault/<vault-uuid>/...(temporary staging area)
Storage Backend: By default, files are stored locally. To use S3-compatible storage (e.g., MinIO), set UPLOADER_STORAGE=s3 and configure the S3 options. See docs/LOCAL_S3.md for details.
The API requires an key header. It must be 32 characters (AES-256 key material) and pass validation.
KEY='0123456789abcdef0123456789abcdef'
curl -sS \
-H "key: ${KEY}" \
-F "file=@./path/to/image.png" \
http://localhost:1323/file/uploadResponse shape:
{
"file_name": "example.png",
"preview_url": "http://localhost:1323/file/<uid>?preview=true",
"download_url": "http://localhost:1323/file/<uid>",
"uploaded_at": "2025-01-01T00:00:00Z"
}UID='<uid-from-upload-response>'
curl -sS -H "key: ${KEY}" "http://localhost:1323/file/${UID}" -o original.bin
curl -sS -H "key: ${KEY}" "http://localhost:1323/file/${UID}?preview=true" -o preview.binPOST /file/upload(multipart form field:file)GET /file/:uid(query:preview=true|false)
More details: docs/API.md.
Local S3 setup (MinIO): docs/LOCAL_S3.md.
- Root package: interfaces and core types (
uploader.*) internal/http: Echo server + handlersinternal/storage: storage backends (local filesystem and S3-compatible)internal/encryption: AES-GCM encryption providerinternal/scaler+internal/preview: image scaling + preview generationinternal/db: SQLite-backed filer (metadata store)
Architecture notes: docs/ARCHITECTURE.md.
make test
make fmt
make ci- This service assumes authentication/authorization is handled elsewhere; the encryption key is provided per-request.
- Only common image types are supported today (
image/png,image/jpeg,image/gif).
- Finish CLI (
cmd/cli) - Add S3 storage backend
- Improve error responses + consistent JSON errors
- Streaming encryption (avoid buffering whole files in memory)