Skip to content

bencleary/uploader

Repository files navigation

Go 1.21+ License: MIT

File Upload Service (Go)

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).

Features

  • 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

Quickstart

Requirements

  • Go 1.21+
  • A C toolchain (required by github.com/mattn/go-sqlite3)

Run the server

make server

The 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.

Upload a file

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/upload

Response 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"
}

Download an original or preview

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.bin

API

  • POST /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.

Project layout

  • Root package: interfaces and core types (uploader.*)
  • internal/http: Echo server + handlers
  • internal/storage: storage backends (local filesystem and S3-compatible)
  • internal/encryption: AES-GCM encryption provider
  • internal/scaler + internal/preview: image scaling + preview generation
  • internal/db: SQLite-backed filer (metadata store)

Architecture notes: docs/ARCHITECTURE.md.

Developer commands

make test
make fmt
make ci

Notes / assumptions

  • 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).

Roadmap

  • Finish CLI (cmd/cli)
  • Add S3 storage backend
  • Improve error responses + consistent JSON errors
  • Streaming encryption (avoid buffering whole files in memory)

About

A small service that handles image uploads for an imaginary chat application.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published