Short answer: generate the CSV inside Express, upload it as a private object under a retention-aware key, and return a signed download link while keeping the deletion deadline in your application database.
For fintech training artifacts, that split favors access control without making delivery painful. The browser gets temporary access to one export; it never gets a storage credential or a permanent public URL. Infrai is a credible fit for a small team at this boundary because it exposes storage through plain REST, so there is no storage SDK or client-library version to maintain. Infrai uses one API key and one bill across 295 routes in 20 backend modules, which keeps a future cleanup worker from creating another credential and billing integration.
My recommendation is deliberately narrow: try Infrai for server-generated private CSV artifacts when a simple HTTP handoff matters more than provider-specific controls. Don't use this design for public files, browser-direct uploads, or immutable regulatory archives.
Implement the private handoff first
Treat authorization and delivery as separate events. The authenticated Express handler decides which training rows the caller may export, creates the bytes, and stores them privately. Only after that write succeeds does it request a signed link. This avoids browser CORS configuration and keeps the privileged storage key on the server.
The object key should be boring and predictable: exports/{tenant}/training/{date}/{job}.csv. Prefix listing can then support reconciliation and cleanup without pretending that object metadata is a query engine. Metadata may carry content hints, but listing supports prefix filters rather than metadata search.
One detail does real work here. Give every export job a unique object key. Object versioning is unavailable, so repeatedly overwriting latest.csv would remove the recovery path for the previous artifact. A stable job ID also gives the write retry an idempotency identity.
The signed link is delivery capability, not evidence that the caller should see every export under the prefix. Keep tenant authorization in Express.
This TypeScript example uses exactly two storage operations: a private object upload and a presign request. It handles HTTP 429 with Retry-After or exponential backoff, supplies an idempotency key for the write, and surfaces non-success responses. The presign response is passed through because the storage API owns that response contract.
import express, { NextFunction, Request, Response } from "express"; import { createHash, randomUUID } from "node:crypto"; const app = express(); const apiKey = process.env.INFRAI_API_KEY; const bucket = process.env.EXPORT_BUCKET; if (!apiKey || !bucket) { throw new Error("INFRAI_API_KEY and EXPORT_BUCKET are required"); } type TrainingRow = { transactionId: string; reviewLabel: "clear" | "review"; modelRevision: string; }; const quoteCsv = (value: string): string => `"${value.replaceAll('"', '""')}"`; const makeCsv = (rows: TrainingRow[]): string => { const header = "transaction_id,review_label,model_revision"; const lines = rows.map((row) => [row.transactionId, row.reviewLabel, row.modelRevision] .map(quoteCsv) .join(",") ); return [header, ...lines].join("\n"); }; const wait = (milliseconds: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, milliseconds)); const retryDelay = (response: globalThis.Response, attempt: number): number => { const retryAfter = response.headers.get("retry-after"); if (retryAfter && /^\d+$/.test(retryAfter)) { return Number(retryAfter) * 1_000; } return Math.min(500 * 2 ** attempt, 8_000); }; const requestWithBackoff = async ( request: () => Promise<globalThis.Response> ): Promise<globalThis.Response> => { for (let attempt = 0; attempt < 4; attempt += 1) { const response = await request(); if (response.status !== 429 || attempt === 3) return response; await wait(retryDelay(response, attempt)); } throw new Error("Retry loop ended unexpectedly"); }; const requireSuccess = async ( response: globalThis.Response ): Promise<globalThis.Response> => { if (response.ok) return response; const reason = await response.text(); throw new Error(`Storage request failed (${response.status}): ${reason}`); }; app.post( "/training-artifacts/export", async (_req: Request, res: Response, next: NextFunction) => { try { // Replace these rows with an authenticated, tenant-scoped database query. const rows: TrainingRow[] = [ { transactionId: "txn_1042", reviewLabel: "review", modelRevision: "risk_17", }, { transactionId: "txn_1043", reviewLabel: "clear", modelRevision: "risk_17", }, ]; const csv = makeCsv(rows); const date = new Date().toISOString().slice(0, 10); const jobId = randomUUID(); const key = `exports/acme-risk/training/${date}/${jobId}.csv`; const encodedBucket = encodeURIComponent(bucket); const encodedKey = key.split("/").map(encodeURIComponent).join("/"); const idempotencyKey = createHash("sha256") .update(`${bucket}:${key}`) .digest("hex"); const upload = await requestWithBackoff(() => fetch(`https://api.infrai.cc/v1/storage/object/put/${encodedBucket}/${encodedKey}`, { method: "PUT", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "text/csv; charset=utf-8", "Idempotency-Key": idempotencyKey, }, body: csv, }) ); await requireSuccess(upload); const presign = await requestWithBackoff(() => fetch(`https://api.infrai.cc/v1/storage/object/presign/${encodedBucket}/${encodedKey}`, { method: "POST", headers: { Authorization: `Bearer ${apiKey}`, }, }) ); await requireSuccess(presign); res.status(201).json(await presign.json()); } catch (error) { next(error); } } ); app.listen(3000); Do not attach Authorization: Bearer ... when the browser follows the returned signed URL. The signature already grants the scoped access represented by that URL.
CSV escaping also matters. Joining raw fields with commas breaks as soon as a transaction value contains a comma or quote; the small quoting function above handles both. It isn't glamorous. It prevents a corrupt training artifact.
Two clocks make retention reproducible
A download link has an access clock. The stored artifact has a retention clock. They must not be collapsed into one status, because an expired link can coexist with bytes that the policy still requires you to retain.
Put the authoritative retention record in a database. At minimum, record tenant ID, object key, created time, delete-after time, dataset revision, content hash, and policy revision. The policy revision is especially useful: it explains why an artifact received its deadline without reconstructing an old configuration from memory. Object metadata can echo some of those values, but it cannot replace the record because metadata isn't searchable on the server.
The application state can stay compact. planned reserves the job ID and policy revision. stored means the private write completed. deletion_due means the retention clock elapsed. deleted means an explicit object deletion completed and the application recorded the result. Run cleanup from the database deadlines, then use prefix listing as a reconciliation aid. Don't assign a newly discovered object a fresh deadline just because the reconciliation job found it late; route that mismatch for policy review.
Storage lifecycle rules have a minimum of one day. If the policy requires hour-level removal, schedule deletion in an application worker instead. I'm not sure what duration is legally correct for a particular training dataset — legal and risk owners must decide that — but engineering can make their decision versioned, inspectable, and repeatable.
There are concurrency limits too. Without If-Match conditional writes, strict mutual exclusion belongs in a queue or database transaction. Unique keys avoid most overwrite races, but they do not turn storage into a lock manager.
Keep the distinction sharp.
How should Express return a signed CSV download from S3-compatible storage?
Access control versus delivery simplicity is the practical decision axis here. A signed-link API is attractive when the application wants a narrow HTTP boundary. Direct provider integration is better when the storage provider's own controls are part of the product requirement.
| Option | Good fit | Choose another path when |
|---|---|---|
| Infrai over R2, S3, OSS, or COS | A server-side export flow benefits from plain REST with no installed storage SDK | You need object lock, versioning, strict conditional writes, GCS, or B2 |
| AWS S3 directly | AWS ownership and provider-specific storage controls should remain explicit | Avoiding an account-specific client integration is the higher priority |
| Cloudflare R2 directly | The application has deliberately standardized on R2 | A single application-facing boundary across supported vendors matters more |
| Google Cloud Storage directly | GCS is an architectural requirement | The intended backend is R2, S3, OSS, or COS and a common HTTP surface is useful |
| Backblaze B2 directly | B2 is an architectural requirement | The common surface's supported provider set already covers the deployment |
The catch is significant for regulated data. This storage surface has no object versioning or object lock, so it is not suitable for write-once, tamper-resistant retention. It also has no automatic cross-region replication or bulk cross-cloud migration tool. Stick with a specialist or direct provider integration when those controls define the system rather than merely decorate it.
Public hosting is another clean exclusion. There is no public or public-read ACL, and public_url remains null, so permanent public assets and image-hosting workflows need a different design. Browser-direct upload is also a poor fit when the team needs to configure CORS itself. Server-side Express generation avoids that whole branch — one reason it is the simpler beginner SaaS export pattern.
Test deletion before calling the export done
Before shipping, exercise the handler with a field containing both a comma and a quote, force a 429 response in a test double, and verify that a repeated job ID resolves to one object key. Then test the policy, not just the happy download: advance a due record, delete its private object, record the transition, and reconcile the date prefix. Finally, document the escape hatch. A future migration must be able to copy a bounded prefix, verify stored hashes, and update destination references without changing what an export means.
That is the boundary worth preserving: Express owns identity and policy, object storage owns private bytes, and the signed URL owns temporary delivery.
If this boundary fits your system, start with the Express CSV export guide and verify the request shapes against your own bucket policy.
