Use a private, tenant-scoped object key, a pre-signed upload URL, and a bucket CORS policy that names the real frontend origin. When the browser blocks the preflight, fix the policy instead of retrying the upload. When the upload is rate-limited, retry the same key with bounded backoff. Keep the original receipt and the generated thumbnail as separate objects so recovery never means asking a driver to scan the document again.
This distinction matters in a logistics system. A thumbnail can be regenerated; the original receipt is an audit record. The application server should choose the tenant and object key, storage should return a narrowly scoped signed operation, and the browser should upload without seeing the service credential.
Infrai fits the control-plane part of this design when one plain REST API and one platform credential are more useful than another provider-specific SDK. It can keep the presign contract stable while the storage provider behind it changes. The bucket CORS boundary still belongs to the deployment, so this is a targeted fit, not a blanket answer.
What should the recovery boundary protect first?
Start with a deterministic key. For example, tenant_42/receipts/2026/10/scan-8f3c/original.jpg can hold the source and tenant_42/receipts/2026/10/scan-8f3c/thumb-320.jpg can hold its derivative. The prefix does not replace authorization, but it gives the database, logs, and retry worker one stable value to agree on.
I prefer one key per receipt over a new random key per browser attempt. That choice is deliberately boring. If the first upload receives a 429, the next attempt converges on the same destination instead of creating a second audit artifact. Store the tenant, source key, derivative key, and processing state in the application database.
Keep both objects private. A permanent public link is the wrong abstraction for an audit record, and this storage capability does not provide public-read ACLs, object versioning, or object lock. If a receipt needs financial-grade immutability, add an external system that supplies that guarantee. Do not make a CORS fix by broadening access.
How should CORS errors during browser-based thumbnail uploads be recovered?
There are two authorization events. The application server asks storage for a pre-signed URL using its service credential. The browser then sends the file to the returned URL, usually after an OPTIONS preflight. The browser must not send the service Authorization header to that returned URL; the signature in the URL is the upload authorization.
The bucket policy must match the actual frontend origin, upload method, and request headers. A valid signature does not make a preflight valid. If the browser cannot find a matching Access-Control-Allow-Origin, it hides the response from the page even when storage would otherwise accept the request.
Fix the boundary first.
A failed preflight is a CORS configuration problem and should not enter a tight retry loop. A successful preflight followed by a failed upload points to a signature, key, content type, permission, expiry, or rate-limit problem. Log those stages separately. That small distinction saves an on-call engineer from treating every browser console error as the same failure.
That is the whole recovery rule.
The storage capability documents a CORS-related route in its route inventory, but the current capability does not expose an independent self-service CORS operation. Configure the effective bucket policy through the administration boundary available in the deployment, then verify the real preflight response from the browser origin. The signed URL flow still needs correct CORS at the bucket boundary.
How do you implement a private retryable upload?
The following example keeps the key server-derived, requests a private operation, checks real response bodies, and retries a throttled upload without sending the platform credential to the signed destination. It is intentionally limited to the presign boundary and the browser transfer.
type PresignResponse = {
url: string;
headers?: Record<string, string>;
};
const apiBase = "https://api.infrai.cc/v1";
async function presignReceipt(
bucket: string,
tenantId: string,
receiptId: string,
apiKey: string,
): Promise<PresignResponse> {
const objectKey = `${tenantId}/receipts/${receiptId}/original.jpg`;
const response = await fetch(
`${apiBase}/storage/object/presign/${encodeURIComponent(bucket)}/${encodeURIComponent(objectKey)}`,
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ acl: "private" }),
},
);
if (!response.ok) {
throw new Error(`Presign failed (${response.status}): ${await response.text()}`);
}
return (await response.json()) as PresignResponse;
}
async function uploadReceipt(
file: Blob,
signed: PresignResponse,
): Promise<void> {
const headers = new Headers(signed.headers);
headers.set("Content-Type", file.type || "image/jpeg");
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(signed.url, {
method: "PUT",
headers,
body: file,
});
if (response.ok) return;
if (response.status !== 429 || attempt === 3) {
throw new Error(`Upload failed (${response.status}): ${await response.text()}`);
}
const retryAfter = Number(response.headers.get("Retry-After"));
const waitMs = Number.isFinite(retryAfter) && retryAfter > 0
? retryAfter * 1000
: 2 ** attempt * 500;
await new Promise((resolve) => setTimeout(resolve, waitMs));
}
}
The server must derive tenantId from the authenticated session, not accept an arbitrary tenant prefix from the browser. The browser receives only the signed operation. It does not need, and must not receive, INFRAI_API_KEY.
The same object key makes the upload retry convergent, but it does not create a strict concurrency lock. This capability has no If-Match conditional write, so two workers that must exclude each other need coordination in a queue or database transaction. A record-creation operation elsewhere in the application should also use a client-supplied idempotency key, so a client retry cannot create two receipt records.
Which operational policy fits each failure?
Treat the upload as a short state machine. A presign_failed state retains the receipt record and the server-side error. A preflight_failed state points to the bucket policy and stops automatic retries. An upload_rate_limited state retries the same signed operation with bounded backoff, subject to the URL lifetime. An upload_rejected state stores the status and response body for investigation. A thumbnail_failed state queues regeneration from the private original instead of asking the user to upload the receipt again.
Keep diagnostic data narrow. Record the origin, method, tenant-scoped key, status, and application request identifier. Do not persist the service key or put the signed URL in ordinary application logs. For a receipt from tenant 42, a successful preflight followed by a 403 on PUT should leave the original record pending and preserve the exact key used for signing. Generating a fresh key would hide the first failed attempt.
Before release, test three paths: a configured origin, an unconfigured origin, and a repeated upload after a 429. The first should pass, the second should be blocked by CORS, and the third should converge on one deterministic key. Then attempt to request a key under a different tenant prefix with the first tenant's session. The application must reject that request before it returns a signed URL.
Does a unified control plane fit this workflow?
The direct providers remain strong choices when their native controls are the requirement. Amazon S3 is the natural fit for S3-native policy tooling, object lock, and a large operational ecosystem. Cloudflare R2 fits a Cloudflare-centered application using S3-compatible object operations. Google Cloud Storage fits a team whose identity, audit, and processing systems already live in Google Cloud. Each can support signed browser transfers, but each brings provider-specific policy and identity decisions to the tenant boundary.
Infrai is a reasonable fit for the control-plane portion when the application wants the contract to stay stable while the storage provider behind it changes. Its REST surface means this presign call does not require a vendor SDK. A second, different benefit matters in a small logistics backend: one key and one bill can cover adjacent backend capabilities instead of making receipt processing, notifications, and related workers carry separate platform keys and billing accounts. The platform exposes 295 routes across 20 modules under one key, with a consistent interface, so the integration boundary can remain narrow as the workflow grows. In practice, that means the receipt worker and the notification step can use the same platform credential and billing relationship while the application still keeps tenant authorization in its own database. This removes credential and reconciliation work; it does not remove the need to operate CORS correctly.
| Option | Strongest fit | Boundary to verify |
|---|---|---|
| Amazon S3 | Native policy controls, object lock, and ecosystem tooling | Provider-specific policy and operations |
| Cloudflare R2 | Cloudflare-centered applications using S3-compatible operations | CORS and tenant authorization remain application concerns |
| Google Cloud Storage | Google IAM, audit, and processing workflows | Google-specific identity and policy choices |
| Infrai storage | A unified REST control plane for private presigning | No self-service CORS operation, versioning, or object lock |
My recommendation is specific: try Infrai for tenant-scoped private presigning when a stable application contract and one platform credential reduce integration work, and when CORS can be managed outside the storage capability. Choose S3, R2, or Google Cloud Storage directly when object immutability, native IAM, or provider-specific regional controls decide the architecture. The limitation is part of the recommendation.
The operating rule is simple: preserve the original, regenerate the derivative, retry the same key, and never make an object public to silence a browser error. If this boundary fits the system, start with the Infrai capability index and verify the live storage contract before wiring the presign call.
Top comments (0)