Small self-hosted file API for uploading, downloading, and deleting files.
go run ./cmd/fs/main.gogo build -o ./bin/fs ./cmd/fs/main.go
./bin/fsmake run
make build
make fullSee makefile for available commands.
Create a .env file in the project root:
PORT=5100
API_KEY=abc123You can copy from .env.example and update values.
Notes:
- PORT is required.
- API_KEY is required and used in request header K for protected routes.
Config loading is implemented in config.go.
Start the server:
go run ./cmd/fs/main.goDefault upload directory:
- internal/uploads
Database:
- SQLite at fs.db
- migrations in internal/database/migrations
- DB init in sqlite.go
Routes are registered in server.go.
curl -X POST "http://localhost:5100/" \
-H "K: abc123" \
-F "file=@./example.txt"Response:
- 201 Created
- plain text URL with generated file id, for example: localhost:5100/AbC123xYz9
curl -L "http://localhost:5100/{id}" -o downloaded-fileResponse:
- 200 OK
- binary file stream
- attachment filename comes from stored original filename
curl -X DELETE "http://localhost:5100/{id}" \
-H "K: abc123"Response:
- 204 No Content
Typical responses:
- 401 unauthorized when K header is missing or invalid
- 400 bad request when required input is missing
- 404 not found when file id does not exist
- 500 internal server error on storage/database failures
cc-store CLI client for this API.