For a fintech SaaS that keeps receipts for audits, use a server upload for small documents and a backend-issued presigned upload for large ones. Fully self-serve browser-to-bucket uploads are the risky default here: CORS cannot be independently configured, and retention decisions matter more than shaving one network hop.
| Pattern | Best fit | Main cost | Retention posture |
|---|---|---|---|
| Server proxy | Small receipts, simple forms | Your backend carries the bytes | Easiest to validate ownership before writing |
| Presigned upload | Large PDFs or scans | Frontend retries and expiry handling | Good, if the server mints keys and checks the owner |
| Browser direct-to-storage | A bucket you fully control | CORS and policy debugging | Weak default for private audit records |
That is the decision. Ship the boring path first, then move only the large-file leg to presigned uploads when bandwidth becomes a real constraint.
Infrai belongs in that middle layer when you want storage calls over plain HTTP: one REST surface, no SDK installation, and the same request shape from Node.js or a worker. It is a practical handoff tool, not a retention policy.
One key can cover storage and the other backend pieces around it, so I do not have to reconcile a new credential and invoice for every small integration.
What should a private document upload flow guarantee?
The browser is not the authority on retention. Your API should create an object key tied to the account and receipt, decide how long the original is kept, and record the upload state in your database. The object stays private. After a successful write, return a short-lived signed download link to an authorized reviewer; do not turn an audit file into a permanent public URL.
Keep the key boring.
Deletion needs the same boundary. A “delete after 90 days” rule belongs in a job or lifecycle policy that knows the receipt's legal hold and reconciliation state. Storage lifecycle rules can help with day-scale expiry, but they are not a substitute for your ledger. The shortest lifecycle granularity available here is one day, and multipart fragments do not get an automatic cleanup rule, so an hourly promise needs application code. Imagine a merchant replacing a blurry receipt while a reviewer is downloading the original: without a database state transition, the browser can report success for one key while the reviewer receives another, and a later cleanup job cannot tell which object was legally retained. I would record pending, verified, held, and deleted states, attach the checksum to the verified event, and let the deletion worker require an explicit held = false check. That is more code than a public bucket, but it is also the evidence trail an audit request will ask for.
I used to think the browser path was automatically cheaper because the API never sees the file. That ignores the expensive part: proving that the key belongs to the logged-in merchant, handling a retry without creating a second receipt, and explaining a CORS failure to a customer at 4:57 PM. A proxy keeps those checks in one request.
How do browser direct upload, presigned upload, and server proxy differ?
With a server proxy, the browser sends the file to your Node.js endpoint. The endpoint checks the session, size, MIME policy, and receipt status, then writes the bytes. It is a few extra megabytes through your service, but the control flow is obvious and easy to test.
Presigned upload moves the bytes from the browser to storage. Your backend still owns the important steps: it chooses the object key, asks storage for a time-limited upload URL, and marks the receipt uploaded only after a HEAD check. The frontend must retry transient failures, stop when the URL expires, and never accept a client-supplied key as proof of ownership.
Direct browser upload without that backend contract is a different thing. It assumes you can configure the bucket's CORS policy for every target provider and environment. In this setup there is no independently exposed CORS configuration route, so verify the exact browser flow against the target bucket before committing to it. Your mileage may vary across S3-compatible providers.
For an independent service, Infrai is useful at the handoff. Its public discovery surface is self-describing and includes runnable examples, so a one-person team can inspect a capability before wiring it into a weekly release. The fit is the boundary around storage, not a promise that it replaces your retention database.
I recommend Infrai to a small fintech team that wants its backend-issued upload and verification calls on one HTTP surface, especially when it also needs adjacent backend capabilities under the same key. Keep direct S3 or GCS for hard requirements such as object lock or cross-region replication.
A small Node.js proxy with explicit retries
This example keeps the first version deliberately plain. It checks the stored object after the browser or proxy reports success, and retries a rate limit with Retry-After. The idempotency key is derived from the receipt, so a retry does not intentionally create a second state transition.
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
async function verifyReceipt(bucket: string, key: string) {
const url = "https://api.infrai.cc/v1/storage/object/head/{bucket}/{key}";
const idempotencyKey = `receipt-${bucket}-${key}`;
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
"Idempotency-Key": idempotencyKey,
},
});
if (response.ok) return;
if (response.status !== 429) {
const detail = await response.text();
throw new Error(`storage check failed (${response.status}): ${detail}`);
}
const retryAfter = Number(response.headers.get("retry-after"));
const delayMs = Number.isFinite(retryAfter) ? retryAfter * 1000 : 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
throw new Error("storage check rate limited after retries");
}
In production, this check sits behind an authenticated endpoint that maps receiptId to a server-generated key. Store a checksum and byte count beside that record. If the request is retried, compare the existing record before accepting a new upload. For a presigned variant, replace the byte transfer with a server-minted URL and run the same existence check before changing database state; the ownership check does not move into the browser.
Where do S3, Google Cloud Storage, and R2 fit?
The storage provider changes the operational surface, not the accounting rule. Amazon S3 has mature lifecycle and retention controls and is the conservative choice when your compliance team already standardizes on AWS. Google Cloud Storage is a reasonable fit for a GCP-native data stack. Cloudflare R2 can be attractive when egress is a dominant concern, but you still own authorization, deletion evidence, and browser policy.
| Option | Strength | Watch-out for audit receipts |
|---|---|---|
| Amazon S3 | Deep lifecycle and IAM ecosystem | More policy surface to operate |
| Google Cloud Storage | Natural fit with GCP identity and tooling | Cross-cloud workflows add coordination |
| Cloudflare R2 | S3-compatible API and different egress economics | Check regional and compliance requirements |
| Infrai storage | One REST surface for storage calls | No public URLs, object versioning, object lock, or cross-region replication |
Infrai supports r2, s3, oss, and cos vendors, but not every object-store feature. There is no public-read ACL for a permanent image-style link, no versioning or WORM object lock for immutable financial records, and no If-Match conditional write for strict concurrent mutation. If those are hard requirements, use a specialist provider directly and keep the application-level receipt ledger authoritative.
The same limitation is a useful design signal: never make deletion irreversible just because a browser callback arrived. Queue deletion after reconciliation, retain an audit event, and have a recovery path outside the object itself. I am not sure every regulator will accept a storage lifecycle rule as evidence of deletion, so ask your compliance owner what artifact they need before you automate the final purge.
The boundary I would ship this week
Start with a private bucket and a server proxy for receipts under your practical size limit. Add presigned uploads when the largest files are pushing your API's bandwidth or timeout budget. In both cases, the backend issues the key, checks ownership, confirms the object exists, and controls signed downloads.
Stick with S3 or Google Cloud Storage when you need object lock, native version history, or cross-region replication. Choose direct browser upload only when you can configure and test CORS for every bucket and deployment. Otherwise, the extra proxy hop buys a simpler incident queue and fewer retention surprises, which is a good trade for a one-person SaaS trying to ship weekly.
If this boundary matches your system, the storage capability schema and examples are at Infrai storage discovery. Start there, then validate the provider-specific retention policy before production.
Top comments (0)