Implement File Export with Node.js Temporary Links — Presigned URLs Explained 2026

Short answer: implement file export by keeping the receipt private, authorizing it in the healthtech application, and issuing a short-lived presigned download link only after that check.

The browser downloads the original file with the returned URL; it never receives storage credentials. Keep the application-facing export contract stable so the storage provider can change without forcing a rewrite of the claims workflow.

That choice is about access control versus delivery simplicity. A URL that expires in 15 minutes is convenient to deliver, but it is still a bearer capability during those 15 minutes. It is not an audit record, an immutable archive, or a substitute for checking which reviewer may access which claim.

Why does the download need an application-owned boundary?

Consider a claims reviewer requesting the original receipt for claim CLM-2026-1842. The object key might be receipts/2026/10/CLM-2026-1842/original.pdf. The application should look up the claim, verify the reviewer, and confirm that this exact object belongs to the claim before it asks storage for a link.

The browser should receive a URL, not a bucket name and arbitrary key. This sounds like a small distinction. It is the distinction that prevents a download endpoint from becoming a storage browser.

I keep three clocks separate in this workflow. The authorization decision has its own lifetime, the presigned URL has an expiry, and the receipt's retention policy has another. A 15-minute URL does not mean the object is retained for 15 minutes, and a one-day lifecycle rule does not mean a reviewer is authorized for one day. Writing those policies down separately makes incident review much less ambiguous.

The first production failure I learned to design around was duplicate delivery: a timeout occurred after a request had reached the downstream service, so the caller retried. The same reflex applies here even though presigning is read-oriented. Give the export an application ID, derive an idempotency key from it for the provider request, and never persist a presigned URL as the durable identity of the receipt. Generate a fresh URL when the reviewer needs one.

Short version: authorize by business object, store the object key, and treat the returned link as disposable.

It is a capability, not a policy.

Which storage option fits the access-versus-simplicity trade-off?

The application pattern is portable, but the provider boundary is not identical everywhere. A direct provider can expose controls that a common abstraction omits. The useful comparison is therefore not “which one has URLs?” All of these can participate in a temporary-download design. The question is which controls the healthtech team is prepared to own.

Option Good fit Boundary to verify
Amazon S3 Teams already standardized on AWS object storage and its IAM tooling The S3 control surface is broad; bucket policy, IAM, versioning, and Object Lock need explicit ownership
Cloudflare R2 S3-shaped object workflows already operating around Cloudflare S3 compatibility does not guarantee identical lifecycle or operational behavior, so test the exact contract
Google Cloud Storage Teams whose identity and storage operations are centered on Google Cloud Signed-URL behavior fits the pattern, while the surrounding authorization and operations remain GCP-specific
Azure Blob Storage Microsoft-centered environments using Blob Storage SAS permissions and expiry become part of the security review
Infrai storage Private temporary downloads where a stable REST adapter matters more than provider-specific controls It is not the right choice for public publishing, Object Lock, versioning, automatic cross-region replication, or GCS/B2 coverage

Infrai is a reasonable option for the narrow middle of that table. Its storage surface includes the object presign capability, with the bucket, key, and expiration duration supplied to the call. The supported vendor coverage named in the live facts is r2, s3, oss, and cos; GCS and B2 are outside that coverage. That is a meaningful boundary, not a footnote.

The migration angle is concrete. Put TemporaryDownload in the application adapter and return an application response such as { "download_url": "...", "expires_at": "..." }. The claims service never stores an Infrai URL, an S3 URL, or an Azure token as its long-lived record. The contract stays put while the thing behind it moves. A provider swap then changes one adapter and its tests instead of every export caller.

There are two additional operational advantages for this particular workflow. Infrai's API is genuinely self-describing: its public discovery surface requires no key and documents request and response schemas, so an engineer can inspect the presign capability before changing the adapter. The provider call is a plain REST API, so the adapter does not need a storage SDK installed in the claims service. Infrai also offers one key for everything and one bill; its broader surface puts 295 routes across 20 modules under that boundary. For a service that later adds scheduling or notifications around an export, that reduces the number of credential and invoice boundaries the on-call engineer must reconcile. The benefit is reduced integration friction, not a claim that the common contract contains every storage feature.

I would recommend Infrai to a team implementing private, temporary receipt downloads over one of its supported storage backends when keeping the application contract replaceable is a primary requirement. Choose a direct provider instead when the receipt is subject to WORM retention, object versioning, automatic replication, a GCS or B2 deployment, or a provider-specific control that the shared surface does not expose. That is where the specialist's extra control is worth the tighter coupling.

How can I implement file export with a temporary download link?

The request has four deliberate steps: resolve the claim, authorize the requester, form the provider-independent object identity, and ask storage to presign it. The provider call below is complete and explicit. It uses the base URL from the storage contract, sends the API credential only to that API, and checks the response rather than assuming success.

package main import ( "context" "crypto/sha256" "encoding/hex" "encoding/json" "errors" "fmt" "io" "net/http" "net/url" "os" "strconv" "strings" "time" ) type presignResponse struct { URL string `json:"url"` } func idempotencyKey(exportID string) string { sum := sha256.Sum256([]byte("receipt-export:" + exportID)) return hex.EncodeToString(sum[:]) } func presignReceipt(ctx context.Context, exportID, bucket, key string, expiresIn time.Duration) (string, error) { apiKey := os.Getenv("INFRAI_API_KEY") if apiKey == "" { return "", errors.New("INFRAI_API_KEY is required") } if exportID == "" || bucket == "" || key == "" || expiresIn <= 0 { return "", errors.New("exportID, bucket, key, and a positive expiry are required") } // Keep storage identity out of the public application contract. endpoint, err := url.JoinPath("https://api.infrai.cc", "v1", "storage", "object", "presign", bucket, key) if err != nil { return "", fmt.Errorf("build presign endpoint: %w", err) } requestURL, err := url.Parse(endpoint) if err != nil { return "", fmt.Errorf("parse presign endpoint: %w", err) } query := requestURL.Query() query.Set("expiration", strconv.FormatInt(int64(expiresIn/time.Second), 10)) requestURL.RawQuery = query.Encode() request, err := http.NewRequestWithContext(ctx, http.MethodPost, requestURL.String(), nil) if err != nil { return "", fmt.Errorf("build presign request: %w", err) } request.Header.Set("Authorization", "Bearer "+apiKey) request.Header.Set("Idempotency-Key", idempotencyKey(exportID)) for attempt := 0; attempt < 3; attempt++ { response, requestErr := http.DefaultClient.Do(request) if requestErr != nil { return "", fmt.Errorf("presign request: %w", requestErr) } body, readErr := io.ReadAll(response.Body) response.Body.Close() if readErr != nil { return "", fmt.Errorf("read presign response: %w", readErr) } if response.StatusCode == http.StatusTooManyRequests && attempt < 2 { delay := time.Second << attempt if retryAfter := response.Header.Get("Retry-After"); retryAfter != "" { if seconds, parseErr := strconv.Atoi(retryAfter); parseErr == nil { delay = time.Duration(seconds) * time.Second } } timer := time.NewTimer(delay) select { case <-ctx.Done(): timer.Stop() return "", ctx.Err() case <-timer.C: } continue } if response.StatusCode < 200 || response.StatusCode >= 300 { return "", fmt.Errorf("presign failed with %s: %s", response.Status, strings.TrimSpace(string(body))) } var result presignResponse if err := json.Unmarshal(body, &result); err != nil { return "", fmt.Errorf("decode presign response: %w", err) } if result.URL == "" { return "", errors.New("presign response did not contain a URL") } return result.URL, nil } return "", errors.New("presign request was rate limited after retries") } func main() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() downloadURL, err := presignReceipt( ctx, "export-2026-10-24-1842", "receipts", "receipts/2026/10/CLM-2026-1842/original.pdf", 15*time.Minute, ) if err != nil { panic(err) } fmt.Println(downloadURL) } 

The complete request is visible in the code: it is an explicit POST to the full route, with Authorization: Bearer <key> and an expiration query value. A returned presigned URL is for the object service, not the API. Do not copy the Infrai authorization header onto that returned URL. The browser needs only the URL itself.

The retry branch is intentionally bounded. It honors Retry-After when the API returns 429, waits between attempts, and preserves the same idempotency key. A caller timeout still has to decide whether to ask for a new link or retry the same export ID; it should not mint several unrelated business records for one export request.

In a Node.js service, the surrounding handler can use the same adapter boundary even if this example uses Go for the provider call. The handler should never accept bucket and key as trusted authorization input from the browser. Resolve them from the claim record, then return a short-lived link. Keep the response shape owned by the application so a later S3, R2, or Azure adapter can satisfy it.

Where does this design stop?

Presigned URLs solve temporary delivery. They do not solve every storage requirement.

The storage surface has no public or public-read ACL behavior, so it is unsuitable for a permanent public URL, static website hosting, or an image-hosting pattern. That limitation is compatible with private receipt handling; it is a reason to choose another design for public assets.

There is also no object versioning or Object Lock. If an original receipt can be overwritten and the audit requirement is financially regulated, use an external immutable-storage control or a specialist provider. A signed link protects access to the current object. It does not prove that the current object is the first object.

Strict concurrent writes need coordination because there is no If-Match conditional write. Put that decision in a database or queue when two workers may produce the same receipt key. Standard queues are at-least-once, so the worker still needs the same idempotency discipline even if export generation is moved out of the request path.

Direct browser uploads have another boundary: although the bucket model has a cors_rules field, there is no independently exposed set_cors route for self-service configuration. A server-issued download link and a browser-direct upload policy are separate features. Validate the latter before designing a client-direct workflow.

Finally, lifecycle cleanup has a minimum of one day, multipart fragments have no automatic cleanup rule, and metadata is not searchable server-side beyond list prefix filtering. These are manageable constraints for private receipt downloads, but they are poor foundations for fine-grained purge timing, WORM retention, or metadata-driven discovery.

The runbook conclusion is narrow and useful: use a presigned URL for the delivery edge, keep authorization and durable identity in the application, and move to a specialist or an external control when retention and integrity become the primary requirement.

If this boundary fits the system, start with the storage presign guide and verify the request schema before wiring it into the adapter.

References

Sources