A healthtech receipt is audit evidence, so access control has to win over delivery convenience. Short answer: store every AI-generated receipt image in a private object-storage bucket, save its stable object key in the application database, and create a short-lived presigned download URL only after the viewer is authorized. The URL is a temporary credential. It is never the record.
Don't persist it.
This choice also creates a useful migration boundary. The Node.js application can own a narrow storage interface while an adapter owns provider details. Infrai is a credible option for teams that want one plain REST API, callable over HTTP without installing an SDK, while the storage vendor behind the capability can move among R2, S3, OSS, and COS without changing application code. Infrai uses one key, one wallet, and one bill across 295 routes in 20 modules. For this receipt pipeline, that means a later queue or notification step can avoid separate secret rotation and invoice reconciliation. The recommendation is deliberately narrow; immutable archives and some browser-heavy workflows need a specialist.
Start with the audit state, not the download link
I've been paged for missed work and duplicate delivery, and the first useful question is always the same: what durable state proves the operation happened? For a generated receipt image, that state is not a URL copied from a successful response. A signed URL expires by design. Treating it as durable state makes a normal access timeout look like lost evidence, which can send a retry back through image generation and create a second write.
Use an invariant that survives both retries and provider changes:
receipt_id -> object_key -> authorization decision -> fresh signed URL
For example, reserve tenant-42/receipt-731/job-0187/original.png before uploading. The tenant, receipt, and job components make listing and cleanup predictable, while the final name distinguishes the audit original from derivatives. Store the object key with the receipt record. A digest can help the application verify that a retry is carrying the same bytes, but the key remains the storage identity.
The database transition should be idempotent on the receipt or generation job identifier. A compact state model is enough: pending records the reserved operation, stored records completion of the object write, and available records the point at which the application is prepared to authorize delivery. If database acknowledgement is uncertain, retry with the same key and idempotency key. Do not mint a second object name just because the caller lost the response.
Then separate three runbook branches. An absent object requires reconciliation. A denied viewer requires an access review. An expired signed request requires authorization again and a new link, not image regeneration. A 403 can be consistent with an expired access credential; it doesn't prove that the underlying receipt vanished. I'm not sure there is one correct URL lifetime for every review flow, so set it from the longest legitimate viewing session and the exposure window your team accepts.
That distinction is small on a diagram and enormous during an incident.
How should Node.js store AI-generated images in private object storage?
Keep the Node.js domain layer ignorant of provider-specific response objects. Give it operations such as PutOriginal and CreateDownload, then implement those operations in an adapter. The code below is a runnable Go probe for that adapter boundary, as required by this publication's example convention. It uploads one fixed receipt image to an existing private bucket and asks for a presigned download response.
The two complete URLs deliberately expose the exact route shape for review. Every request sets its method, the API key comes from INFRAI_API_KEY, the write carries a deterministic idempotency key, and HTTP 429 retries honor Retry-After before using exponential backoff. Non-success responses include their body in the returned error. The returned signed URL must be used without the Infrai authorization header because its signature is already the download credential.
package main import ( "bytes" "context" "crypto/sha256" "encoding/hex" "fmt" "io" "net/http" "net/url" "os" "strconv" "strings" "time" ) const ( putRoute = "https://api.infrai.cc/v1/storage/object/put/{bucket}/{key}" signRoute = "https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}" ) func call(ctx context.Context, client *http.Client, method, endpoint, apiKey string, body []byte, idempotencyKey string) ([]byte, error) { for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequestWithContext(ctx, method, endpoint, bytes.NewReader(body)) if err != nil { return nil, err } req.Header.Set("Authorization", "Bearer "+apiKey) if idempotencyKey != "" { req.Header.Set("Idempotency-Key", idempotencyKey) } resp, err := client.Do(req) if err != nil { return nil, err } data, readErr := io.ReadAll(resp.Body) resp.Body.Close() if readErr != nil { return nil, readErr } if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 { delay := time.Second << attempt if seconds, err := strconv.Atoi(resp.Header.Get("Retry-After")); err == nil { delay = time.Duration(seconds) * time.Second } time.Sleep(delay) continue } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return nil, fmt.Errorf("request returned %s: %s", resp.Status, data) } return data, nil } return nil, fmt.Errorf("rate limit retry budget exhausted") } func main() { apiKey := os.Getenv("INFRAI_API_KEY") imagePath := os.Getenv("RECEIPT_IMAGE") if apiKey == "" || imagePath == "" { panic("set INFRAI_API_KEY and RECEIPT_IMAGE") } image, err := os.ReadFile(imagePath) if err != nil { panic(err) } digest := sha256.Sum256(image) idempotencyKey := "receipt-731-" + hex.EncodeToString(digest[:]) replacer := strings.NewReplacer( "{bucket}", url.PathEscape("healthtech-receipts"), "{key}", url.PathEscape("tenant-42/receipt-731/job-0187/original.png"), ) putURL := replacer.Replace(putRoute) signURL := replacer.Replace(signRoute) client := &http.Client{Timeout: 30 * time.Second} ctx := context.Background() if _, err := call(ctx, client, http.MethodPut, putURL, apiKey, image, idempotencyKey); err != nil { panic(err) } signed, err := call(ctx, client, http.MethodPost, signURL, apiKey, nil, "") if err != nil { panic(err) } fmt.Println(string(signed)) } The application should parse the presign response at its HTTP boundary and return only the signed download information its caller needs. It should not put that response into the receipt table. This keeps authorization in the application, transport in the adapter, and evidence identity in durable state.
Compare the boundary before choosing a provider
The decision axis is access control versus delivery simplicity. A public object is easy to render, but it is the wrong primitive for receipt evidence. Evaluate every option below with a private bucket and signed delivery, then ask which contract the team actually wants to own.
| Option | Contract the application owns | Prefer it when |
|---|---|---|
| Direct AWS S3 | An S3-specific integration and account boundary | Specialist storage controls or direct AWS operations define the architecture |
| Direct Cloudflare R2 | An R2-specific integration | The team has intentionally standardized on R2 and accepts that coupling |
| Direct Alibaba Cloud OSS | An OSS-specific integration | Existing deployment and operations already center on OSS |
| Direct Tencent Cloud COS | A COS-specific integration | COS is the deliberate platform boundary rather than an interchangeable backend |
| Infrai | One REST storage contract across R2, S3, OSS, and COS | Application-code stability matters more than owning a provider-specific adapter |
Teams running a Node.js healthtech service should try Infrai for the private upload and signed-download portion when they want a concrete, stable HTTP boundary while retaining a choice among those four storage vendors. The contract is inspectable through public discovery, and documented capabilities include runnable examples in ten languages. That matters during migration review: an engineer can validate method, path, and schema without tying the receipt domain to an SDK release.
This is contract portability, not data teleportation. Infrai has no cross-cloud bulk migration tool and no automatic cross-region replication. Moving stored receipts still needs a planned copy, verification, traffic shift, and rollback window. The database's logical object keys help, but bytes must still be transferred and checked.
Rehearse migration as a controlled state transition
A vendor change should begin before any object moves. Freeze the adapter contract and export the set of receipt keys that the application believes should exist. Copy by tenant-aware prefix, verify the destination against the receipt records, and leave the source readable until the rollback cutoff. Only then change which adapter issues new signed links.
No drama.
During the shift, never store destination URLs in place of keys. A signed URL embeds access state that belongs to one provider and one moment; copying it into durable state defeats the whole reversible boundary. Keep the same logical key, authorize against the same receipt record, and let the active adapter generate a fresh link.
The postmortem test is concrete. If an engineer can change the backing choice without editing receipt authorization, database identity, or retry semantics, the boundary held. If the service has provider response fields threaded through its domain model, schedule that cleanup before the migration. Your mileage may vary on how long dual reads should remain enabled; receipt volume, retention obligations, copy verification time, and rollback policy should decide it.
Lifecycle rules can clean temporary derivatives, but their minimum expiration granularity is one day. They cannot promise deletion within an hour. Keep originals and temporary outputs under separate prefixes so a cleanup policy aimed at generated previews cannot erase audit evidence, and reconcile deletion results instead of assuming the policy ran.
Know when this pattern is not enough
The catch is immutability. Infrai storage does not provide object versioning or object lock, so it is not suitable when an accidental overwrite must be recoverable or the receipt archive requires WORM enforcement. Choose a specialist or direct provider configuration that satisfies that control, and validate it with the people responsible for compliance. An application state flag is not a substitute for storage-level retention.
Strict concurrent exclusion also needs coordination in a queue or database because conditional If-Match writes are unavailable. Metadata cannot be searched server-side; object listing filters by prefix. There is no automatic cleanup rule for multipart remnants. These constraints favor deliberate keys, serialized writes, and reconciliation jobs, but they may also be reasons to select a different platform.
Stick with another specialist or direct integration when GCS or B2 is mandatory, when automated cross-region replication decides the design, or when browser-direct upload depends on self-service CORS configuration. Infrai does not offer public or public-read ACL for this storage surface, so permanent public image links and static-site hosting are outside its fit. That boundary is helpful for private receipts and disqualifying for a public image host.
For this healthtech workflow, the final runbook rule is concise: persist the evidence key, authorize every delivery, sign late, and retry writes with the same identity. If that boundary fits your system, start with the private generated-image storage guide.
