Skip to content

Examples

All examples are available in the examples directory on GitHub.

Start Stowry with the example config:

Terminal window
# From repository root
stowry serve --config examples/config.yaml --db-dsn /tmp/stowry.db --storage-path /tmp/data

Or with Docker:

Terminal window
docker run --rm -p 5708:5708 \
-v $(pwd)/examples/config.yaml:/config.yaml:ro \
ghcr.io/sagarc03/stowry:latest serve --config /config.yaml --db-dsn :memory:

Simple examples showing upload, download, and delete operations with presigned URLs.

package main
import (
"bytes"
"io"
"net/http"
stowry "github.com/sagarc03/stowry-go"
)
func main() {
client := stowry.NewClient(
"http://localhost:5708",
"your-access-key",
"your-secret-key",
)
// Upload a file
key := "/hello.txt"
content := []byte("Hello from stowry-go!")
uploadURL := client.PresignPut(key, 900) // 15 minutes
req, _ := http.NewRequest("PUT", uploadURL, bytes.NewReader(content))
req.Header.Set("Content-Type", "text/plain")
http.DefaultClient.Do(req)
// Download a file
downloadURL := client.PresignGet(key, 900)
resp, _ := http.Get(downloadURL)
data, _ := io.ReadAll(resp.Body)
// Delete a file
deleteURL := client.PresignDelete(key, 900)
req, _ = http.NewRequest("DELETE", deleteURL, nil)
http.DefaultClient.Do(req)
}

Run the full example:

Terminal window
cd examples/go-native
go mod tidy
go run main.go

Stowry supports AWS Signature V4, so you can use AWS SDKs to generate presigned URLs.

import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
cfg := aws.Config{
Region: "us-east-1",
Credentials: credentials.NewStaticCredentialsProvider(
"your-access-key",
"your-secret-key",
"",
),
}
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
o.BaseEndpoint = aws.String("http://localhost:5708")
o.UsePathStyle = true
})
presignClient := s3.NewPresignClient(client)
// Generate presigned PUT URL
putReq, _ := presignClient.PresignPutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String("stowry"),
Key: aws.String("hello.txt"),
})
fmt.Println(putReq.URL)

Full example: examples/go-aws


Full-stack applications demonstrating real-world usage patterns.

A Next.js application using server components and Better Upload for direct browser uploads.

Features:

  • Server-side presigned URL generation
  • Direct browser-to-Stowry uploads
  • File listing with presigned download URLs
  • TypeScript throughout
Terminal window
cd examples/app-nextjs
npm install
npm run dev

View source →

A traditional backend/frontend separation with Flask API and React SPA.

Features:

  • Flask API for presigned URL generation
  • React SPA with file upload/download UI
  • Demonstrates Stowry in SPA mode for serving the frontend
Terminal window
cd examples/app-flask-react
# Start backend
cd backend && pip install -r requirements.txt && flask run
# Start frontend (in another terminal)
cd frontend && npm install && npm run dev

View source →


Stowry supports two signing schemes:

Native signing (stowry-go, stowrypy, stowryjs):

http://localhost:5708/path?X-Stowry-Credential=...&X-Stowry-Signature=...
  • Lightweight, simpler URL format
  • No bucket prefix required in path

AWS Signature V4 (AWS SDKs):

http://localhost:5708/bucket/key?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=...
  • Compatible with existing AWS SDK code
  • Requires path-style addressing (UsePathStyle: true)
  • Python boto3 requires signature_version='s3v4'