Getting Started
Getting Started
Section titled “Getting Started”This guide will have you running Stowry and storing your first file in 5 minutes.
Prerequisites
Section titled “Prerequisites”- A terminal/command line
curlfor making HTTP requests (or any HTTP client)
Step 1: Download Stowry
Section titled “Step 1: Download Stowry”Download the latest release for your platform:
# Linux (amd64)curl -LO https://github.com/sagarc03/stowry/releases/latest/download/stowry-linux-amd64chmod +x stowry-linux-amd64mv stowry-linux-amd64 stowry
# macOS (arm64)curl -LO https://github.com/sagarc03/stowry/releases/latest/download/stowry-darwin-arm64chmod +x stowry-darwin-arm64mv stowry-darwin-arm64 stowryStep 2: Create Configuration
Section titled “Step 2: Create Configuration”Create a config.yaml file:
server: port: 5708 mode: store
database: type: sqlite dsn: stowry.db table: stowry_metadata auto_migrate: true
storage: path: ./data
auth: region: us-east-1 service: s3 keys: - access_key: AKIAIOSFODNN7EXAMPLE secret_key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
access: public_read: false public_write: false
log: level: infoStep 3: Database Setup
Section titled “Step 3: Database Setup”The config above uses auto_migrate: true, which automatically creates the database tables on startup. This is the easiest option for getting started.
The table name (stowry_metadata in this example) can be anything you want - just make sure it matches between your config and the SQL schema.
Alternative: Manual Migration
If you prefer to manage the schema yourself, remove auto_migrate: true and run the SQL manually (replace stowry_metadata with your chosen table name):
CREATE TABLE IF NOT EXISTS stowry_metadata ( id TEXT NOT NULL PRIMARY KEY, path TEXT NOT NULL UNIQUE, content_type TEXT NOT NULL, etag TEXT NOT NULL, file_size_bytes INTEGER NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL, deleted_at TEXT, cleaned_up_at TEXT);
CREATE INDEX IF NOT EXISTS idx_stowry_metadata_deleted_atON stowry_metadata (deleted_at);
CREATE INDEX IF NOT EXISTS idx_stowry_metadata_pending_cleanupON stowry_metadata (deleted_at, cleaned_up_at);
CREATE INDEX IF NOT EXISTS idx_stowry_metadata_active_listON stowry_metadata (created_at, path);CREATE TABLE IF NOT EXISTS stowry_metadata ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), path TEXT NOT NULL UNIQUE, content_type TEXT NOT NULL, etag TEXT NOT NULL, file_size_bytes BIGINT NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), deleted_at TIMESTAMPTZ, cleaned_up_at TIMESTAMPTZ);
CREATE INDEX IF NOT EXISTS idx_stowry_metadata_deleted_atON stowry_metadata (deleted_at)WHERE (deleted_at IS NOT NULL);
CREATE INDEX IF NOT EXISTS idx_stowry_metadata_pending_cleanupON stowry_metadata (deleted_at, cleaned_up_at)WHERE (deleted_at IS NOT NULL AND cleaned_up_at IS NULL);
CREATE INDEX IF NOT EXISTS idx_stowry_metadata_active_listON stowry_metadata (created_at, path)WHERE (deleted_at IS NULL);Step 4: Start the Server
Section titled “Step 4: Start the Server”./stowry serveYou should see:
INFO starting server addr=:5708 mode=storeStep 5: Upload a File
Section titled “Step 5: Upload a File”Stowry uses presigned URLs for authentication. For this quick test, enable public write access temporarily by setting public_write: true in your config, then restart the server.
Upload a file:
curl -X PUT \ -H "Content-Type: text/plain" \ -d "Hello, Stowry!" \ http://localhost:5708/hello.txtResponse:
{ "id": "550e8400-e29b-41d4-a716-446655440000", "path": "hello.txt", "content_type": "text/plain", "etag": "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e", "file_size_bytes": 14, "created_at": "2024-01-15T10:30:00Z", "updated_at": "2024-01-15T10:30:00Z"}Step 6: Download the File
Section titled “Step 6: Download the File”curl http://localhost:5708/hello.txtOutput:
Hello, Stowry!Step 7: Use Presigned URLs (Production)
Section titled “Step 7: Use Presigned URLs (Production)”For production, disable public access and use presigned URLs. See the Authentication guide for generating presigned URLs with the stowry-go SDK or AWS SDK.
import stowry "github.com/sagarc03/stowry-go"
client := stowry.NewClient( "http://localhost:5708", "AKIAIOSFODNN7EXAMPLE", "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",)
// Generate a presigned URL valid for 15 minutesuploadURL := client.PresignPut("/photos/vacation.jpg", 900)Next Steps
Section titled “Next Steps”- Installation - More installation options
- Configuration - Full configuration reference
- Authentication - Presigned URL authentication
- Server Modes - Store, Static, and SPA modes