Supabase Storage

Use Supabase Storage as a Files SDK backend through the Storage HTTP API.

Create the adapter

package main

import (
	"context"

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

func newClient(ctx context.Context) (*files.Client, error) {
	adapter, err := supabase.New(supabase.Options{
		Bucket: "uploads",
	})
	if err != nil {
		return nil, err
	}

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

Environment variables

When options are empty, the adapter reads:

VariablePurpose
SUPABASE_URLSupabase project URL.
NEXT_PUBLIC_SUPABASE_URLProject URL fallback.
SUPABASE_SERVICE_ROLE_KEYPreferred key for server-side writes.
SUPABASE_KEYAlternative API key fallback.
NEXT_PUBLIC_SUPABASE_ANON_KEYAnon key fallback for public bucket use cases.

Buckets must already exist. Use a service role key for writes to buckets protected by RLS.

Public URLs

By default, URL creates a signed read URL. For public buckets, set Public: true to return the Supabase public object URL. Use PublicBaseURL when a CDN fronts the bucket.

adapter, err := supabase.New(supabase.Options{
	Bucket:        "uploads",
	PublicBaseURL: "https://cdn.example.com",
})

ResponseContentDisposition forces the signed path so the disposition is bound into the URL. Supabase only supports attachment-style download overrides.

Resumable uploads

Supabase resumable uploads use TUS through files.UploadControl. The adapter uses a 6 MiB minimum part size.

control := files.NewUploadControl()

_, err := client.Upload(ctx, "videos/intro.mp4", files.FileBody("intro.mp4"), files.UploadOptions{
	ContentType: "video/mp4",
	Control:     control,
})

Compatibility

MethodStatusNotes
uploadYesSupports content type, cache-control, user metadata, and progress.
downloadYesRange reads are not advertised.
deleteYesBulk delete uses Supabase's batch remove endpoint.
listYesUses the V2 list API; directory-style listing supports /.
searchYesUses SDK list/search behavior.
headYesUses Supabase object info and exposes a lazy body.
existsYesReturns false only for provider NotFound responses.
copyYesUses Supabase server-side copy.
urlPartialSigned URLs by default; public bucket/CDN fast paths when configured.
signedUploadUrlPartialReturns a PUT URL with x-upsert: true; size limits are not supported.

On this page