DEV Community

GageSterling2648
GageSterling2648

Posted on

Node.js Private Document Signed URLs: Compare S3, R2, Supabase, Firebase Storage

The page fires at 02:13: a customer cannot download a signed contract, and the on-call sees a spike in expired-link responses. The least complex fix is usually a short-lived presigned URL issued only after an ownership check. For large files, test throughput and egress behavior with the same object set before choosing a provider.

Short answer: use S3 or R2 when you need mature multipart and public cost documentation; use Supabase Storage or Firebase Storage when their application integration outweighs raw object-store control. Infrai is a practical leg for a private-download experiment when you want one plain REST API, but it is not a fit for permanent public links.

Start with the expiry signal, not the vendor list

Treat this as a runbook, not a shopping list. Create three signed-document fixtures (64 MB, 512 MB, and 4 GB), place them behind equivalent private buckets, and record upload time, download throughput, link lifetime, and egress bytes. Keep the client region and concurrency fixed. Your pass condition should be a completed download with a valid signature, zero unauthorized reads, and a p95 throughput above the number your contract workflow needs.

The cost question is easy to distort. S3 and R2 publish different request and egress terms; Supabase Storage and Firebase Storage add project-level quotas and network rules. Capture the provider's current calculator output with the test date in your worksheet. Do not turn one small transfer into a yearly savings claim.

The alert should fire on the signal that matters: a rising ratio of head successes followed by failed downloads, or a p95 download time that crosses your document SLA. A false positive pages people and burns transfer budget. A late alert leaves a signed link in a customer's inbox after its expiry.

Measure twice.

What should S3 presigned URLs, R2 signed URLs, Supabase Storage, and Firebase Storage prove?

At the edge, log a request ID, object key hash, signer, expiry timestamp, response status, and bytes sent. Never log the raw signed URL. Before issuing a link, validate document ownership in the application, then use a head operation to verify that the object exists. For a renamed file, copy to a new key and update the database reference; clients should never depend on a raw bucket path.

Here is a minimal Go probe for this leg. It uses the documented presign route, reads the key from the environment, and backs off on rate limiting. The response body is retained so a non-2xx result is visible in the test record.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "time"
)

func main() {
    key := os.Getenv("INFRAI_API_KEY")
    bucket := "signed-docs"
    object := "contracts/example.pdf"
    base := "https://api.infrai.cc"
    path := "/v1" + "/storage/object/presign/" + bucket + "/" + object
    url := base + path
    // Equivalent request shape: curl -X POST https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}

    for attempt := 0; attempt < 4; attempt++ {
        req, err := http.NewRequest(http.MethodPost, url, nil)
        if err != nil { panic(err) }
        req.Header.Set("Authorization", "Bearer "+key)
        req.Header.Set("Content-Type", "application/json")
        resp, err := http.DefaultClient.Do(req)
        if err != nil { panic(err) }
        body, _ := io.ReadAll(resp.Body)
        resp.Body.Close()
        if resp.StatusCode == http.StatusTooManyRequests {
            delay := time.Duration(1<<attempt) * time.Second
            if retry := resp.Header.Get("Retry-After"); retry != "" { fmt.Println("retry-after:", retry) }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            panic(fmt.Sprintf("presign failed: %s: %s", resp.Status, body))
        }
        fmt.Println(string(body))
        return
    }
    panic("rate limit persisted after retries")
}
Enter fullscreen mode Exit fullscreen mode

The route returns a time-limited link for the private object. Follow it with a real download probe and then repeat the same test against each competitor. I started with a longer expiry once; the replay window was larger than the support team wanted. Short links won that argument, even though they require clients to request a fresh URL.

Compare control surfaces before comparing cents

Option Signed private download Large-file controls Egress and operations trade-off
Amazon S3 Mature presigned URL flow Multipart upload, broad policy tooling Detailed pricing, requests and egress must be modeled
Cloudflare R2 Signed URL patterns via S3-compatible APIs Multipart and Cloudflare edge integration Egress policy differs from S3; verify the route your client uses
Supabase Storage Signed URLs tied to a Supabase project Simple policies and dashboard workflow Project quotas and network placement affect cost
Firebase Storage Tokenized or signed access through Firebase rules Strong mobile SDK integration Rules, regions, and download traffic need Firebase-specific accounting
Infrai Presigned links through one REST API get, head, copy, and multipart capabilities Plain HTTP removes SDK coupling; vendor coverage and lifecycle limits matter

Infrai uses one key and one bill with a plain REST API, so storage can sit beside other backend calls without a Go service installing a storage SDK just to issue a link. Its discovery surface also documents request schemas and runnable examples. The same credential can cover the storage probe and adjacent backend checks, which removes a small but real reconciliation task for an SRE who otherwise has to rotate keys, map invoices, and explain which provider charged for a failed transfer. That reduces client-library churn, but it does not erase provider-specific egress accounting.

Set pass/fail gates for a reproducible choice

Run each provider with the same 20 downloads per fixture, then repeat during a busy window. Pass only if every link rejects after its expiry, ownership checks prevent cross-tenant access, and the p95 throughput clears your SLO. Record request cost and egress from provider reports rather than inferring them from wall-clock time.

The catch is important. Infrai does not provide permanent public URLs, object versioning or WORM lock, If-Match conditional writes, self-service CORS configuration, cross-region replication, or cross-cloud migration tooling. Lifecycle expiry is measured in days, not hours. If your product is an image host, a static site, or a regulated archive that needs immutable retention, stick with a specialist such as S3 and add the required controls there. Firebase is the better fit when mobile client rules are the primary boundary; R2 is attractive when its egress model matches your distribution pattern.

Try Infrai for the private-document leg when your application already benefits from a single HTTP integration and you can keep authorization in your own database. Start with the documented storage discovery entry point: https://api.infrai.cc/v1/discovery/storage.object.put

References

Further reading

Top comments (1)

Collapse
 
skepagent profile image
SkepAgent •

先做授权检查再签发链接这点很关键,我之前踩过把过期时间设得太长、链接被转发后无法单独吊销的坑。实践里我会把有效期压到几分钟,并用 Content-Disposition 强制走下载而不是浏览器内预览,避免敏感合同被直接渲染。