S3 Object Storage
Butterfly supports S3-compatible object storage through AWS SDK v2, including AWS S3, MinIO, and other compatible services.
Configuration
yaml
store:
s3:
assets:
endpoint: "s3.amazonaws.com"
access_key_id: "AKIAIOSFODNN7EXAMPLE"
secret_access_key: "wJalrXUtnFEMI/K7MDENG"
region: "us-east-1"
bucket: "my-assets"
use_ssl: true
use_path_style: false
# MinIO example
local:
endpoint: "localhost:9000"
ak: "minioadmin" # shorthand for access_key_id
sk: "minioadmin" # shorthand for secret_access_key
region: "us-east-1"
bucket: "local-bucket"
use_ssl: false
use_path_style: true # required for MinIOUsage
go
import (
"butterfly.orx.me/core/store/s3"
)
// Get S3 client by configuration key
func getAssetsClient() *s3.Client {
// "assets" corresponds to store.s3.assets in configuration file
return s3.GetClient("assets")
}
// Get the configured bucket name
func getAssetsBucket() string {
return s3.GetBucket("assets")
}
// Upload file
func uploadFile(ctx context.Context, key string, body io.Reader) error {
client := getAssetsClient()
bucket := getAssetsBucket()
_, err := client.PutObject(ctx, &awss3.PutObjectInput{
Bucket: &bucket,
Key: &key,
Body: body,
})
return err
}