All articles

Supabase Storage and S3: signed HTTP requests, streaming and caching

From buckets and object keys to SigV4 signing: streaming with .NET HttpClient, classifying errors and caching immutable content.

t.Turgay
Supabase Storage and S3: signed HTTP requests, streaming and caching

Object storage addresses file bytes with a bucket and an object key. A relational database can describe ownership and relationships while Storage carries the payload. Working with the S3-compatible interface in Supabase requires understanding HTTP operations, request signing, stream ownership and cache semantics. The examples below are independent teaching fragments that explain those protocol boundaries in .NET.

Buckets, object keys and path-style addressing

A bucket contains objects, and an object key is the full identifier inside that container. Slashes in assets/atlas.png do not imply real filesystem directories. Server-generated identifiers reduce accidental collisions and avoid treating an uploaded filename as an authoritative storage path.

Path-style addressing combines the endpoint, bucket and key. Spaces, Unicode and percent signs make encoding important. The canonical path used for signing must describe the path actually transmitted. Encoding a path twice can produce a signature failure even when the intended object identifier looks correct.

# Address template; replace placeholders with server configuration.
https://<project-ref>.storage.supabase.co/storage/v1/s3/<bucket>/<key>

PUT    /<bucket>/<key>   # write object bytes
GET    /<bucket>/<key>   # read object bytes
HEAD   /<bucket>/<key>   # read response metadata
DELETE /<bucket>/<key>   # remove the object

Supabase — S3 compatibility

What does SigV4 sign?

SigV4 combines the HTTP method, canonical URI, sorted query parameters, normalized headers, signed-header list and payload hash. The canonical-request hash enters a string-to-sign. Date, region and the s3 service identify the credential scope, and an HMAC-derived signing key produces the signature.

The timestamp uses UTC. Changing a signed header after signing invalidates the request. So does hashing one payload and transmitting different bytes. Diagnose the normalized request fields, region and clock offset without logging the secret signing material.

AWS — creating a SigV4 request

S3 credentials and browser sessions have separate boundaries

Generated S3 credentials stay in server configuration. Giving the browser an application content URL avoids turning a file-read requirement into broad storage access. Read the credential permission model explicitly instead of assuming that a generated key is restricted to one bucket.

An API may serve a publicly readable response backed by a private bucket. Bucket access and the response audience are separate decisions. Storage authentication obtains the bytes; application authorization decides whether the caller may receive them.

Supabase — S3 authentication

Read responses as streams with HttpClient

ResponseHeadersRead lets SendAsync complete before buffering the entire response body. Reading still continues afterward, so the response and its stream require a clear lifetime. This fragment assumes that request is already signed and that the caller owns destination and a reused http client.

Cancellation is passed to both sending and copying. Define a cancellation budget for the complete operation rather than assuming that the client timeout bounds every later stream read. Reusing HttpClient also preserves connection pooling instead of recreating a pool for every file.

// request is already signed; destination is owned by the caller.
using var response = await http.SendAsync(
    request, HttpCompletionOption.ResponseHeadersRead, ct);
response.EnsureSuccessStatusCode();
await using var source = await response.Content.ReadAsStreamAsync(ct);
await source.CopyToAsync(destination, ct);

Microsoft Learn — HttpClient guidelines

Hashes, ETags and immutable caching

SHA-256 can compare payload content. Equal byte lengths do not prove equal content. An ETag is an HTTP representation validator and should not automatically be interpreted as a SHA-256 digest.

An immutable cache policy promises that the representation at that URL will not change while fresh. New content therefore needs a new key or versioned URL. A matching If-None-Match request can receive 304 and reuse its cached representation without downloading the body again.

// A suitable response policy for a public, versioned object:
Cache-Control: public, max-age=31536000, immutable
ETag: "content-version-identifier"

// A later conditional request:
If-None-Match: "content-version-identifier"

HTTP errors and writes across two stores

A 404 describes a missing object; 403 may reflect permissions, credentials or signature problems. Server failures and network interruptions can be temporary. Mapping every error to missing content hides configuration failures. Retry policy should consider status, repeatability and the remaining time budget.

Uploading bytes and committing PostgreSQL metadata complete in different systems. If the upload succeeds but the database write fails, an orphan object can remain. Write ordering, cleanup and stable object identity belong in the same consistency design. A repeatable PUT does not automatically make the associated database insertion idempotent.

Related technical articles

You have reached the end of this orbit.
Explore more articles
turgay.A little code, a few pixels, a lot of curiosity.© 2026 · Made on Earth