S3-compatible

Configure a generic S3-compatible endpoint with explicit credentials and bucket settings.

Create the adapter

Use s3compatible.New for providers with an S3 API and a custom endpoint.

package main

import (
	"context"

	files "github.com/cersho/gofiles-sdk"
	"github.com/cersho/gofiles-sdk/providers/s3compatible"
)

func newClient(ctx context.Context) (*files.Client, error) {
	adapter, err := s3compatible.New(ctx, s3compatible.Options{
		Name: "minio",
		Bucket: "uploads",
		Region: "us-east-1",
		Endpoint: "https://minio.storage.internal",
		AccessKeyID: "minio-access-key",
		SecretAccessKey: "minio-secret-key",
		ForcePathStyle: true,
	})
	if err != nil {
		return nil, err
	}

	return files.New(files.Options{Adapter: adapter})
}

Environment variables

When credentials are not passed in options, the adapter reads:

VariablePurpose
S3_COMPATIBLE_ACCESS_KEY_IDAccess key ID.
S3_COMPATIBLE_SECRET_ACCESS_KEYSecret access key.

Public URLs

adapter, err := s3compatible.New(ctx, s3compatible.Options{
	Name: "minio",
	Bucket: "uploads",
	Endpoint: "https://minio.storage.internal",
	AccessKeyID: os.Getenv("S3_COMPATIBLE_ACCESS_KEY_ID"),
	SecretAccessKey: os.Getenv("S3_COMPATIBLE_SECRET_ACCESS_KEY"),
	PublicBaseURL: "https://cdn.acme.internal/uploads",
})

On this page