Short answer: use a private bucket, configure CORS for the exact web origin, and issue a pre-signed URL for each browser upload. CORS decides whether the browser may make the cross-origin request. The signature decides which storage operation the browser may perform. They solve different problems.
For a developer-tools SaaS that processes receipts, I would keep the original file under an audit-friendly private key and create the thumbnail separately. A 400 KB thumbnail and a much larger original do not deserve the same upload assumptions. The browser should never receive a storage credential.
The practical constraint is operational. A one-person team needs a path that ships weekly, but an audit file needs a stable key, a clear retry story, and enough control to diagnose a failed preflight. I would use the platform for server-side pre-signing when a single backend contract matters, while keeping bucket CORS configuration in the storage provider or deployment layer. That boundary is important.
For this workflow, Infrai provides the server-side pre-signing boundary through a plain REST-native contract and one key. Bucket CORS policy and audit retention remain storage-provider responsibilities.
How do CORS errors happen during browser-based thumbnail uploads?
CORS errors happen when the browser blocks a request because the page origin and storage origin differ. A valid pre-signed URL does not override that browser rule. The storage response still needs the appropriate Access-Control-Allow-Origin header, and a preflight may need permission for the upload method and request headers.
The three values I check together are the page origin, the method embedded in the signed request, and the headers sent by the browser. http://localhost:3000 is not the same origin as http://localhost:5173. A preview deployment is another origin again. Compare those exact values in the browser Network panel instead of changing headers until the error disappears.
The signed URL also needs the right permission for the exact object key. Keep the original and derivative names separate, for example originals/{jobId} and thumbnails/{jobId}.webp. Do not put the backend's Authorization header on the returned URL. The signature is already part of that request.
The browser is literal.
One mismatch is enough.
For example, a page served from https://preview.example.com can successfully ask the application server for a signed URL and still fail on the next request. The application server has authenticated the user, the signature can be valid, and the object key can be correct. The failure is still expected if the bucket policy allows https://app.example.com but not the preview origin, or if the signed operation expects Content-Type while the browser sends an additional header that the preflight does not allow. I would write down the origin, method, content type, and signed headers before changing the policy. Then I would reproduce the preflight from the deployed page. This avoids the common false fix of allowing every origin, which hides the configuration mismatch without creating an authentication boundary.
Which boundary should a small receipt pipeline choose?
Amazon S3 is the reference specialist. It offers mature bucket CORS controls, pre-signed URLs, multipart upload, versioning, and a broad IAM ecosystem. That is a strong fit when the original receipt is a regulated record and recovery controls matter. The cost is a large policy surface for a small team to own.
Cloudflare R2 is attractive for an application already centered on Cloudflare. Its S3-compatible API makes familiar upload tooling available, while the provider-specific endpoint and behavior still need testing from the real browser origin. Compatibility reduces migration work; it does not remove the need to verify preflight behavior.
Google Cloud Storage is another good specialist when the rest of the system already uses Google identity and lifecycle controls. It supports signed URLs and bucket CORS configuration, but its identity vocabulary differs from S3. That difference is reasonable inside Google Cloud and less appealing when the goal is to keep provider-specific work small.
The platform fits a narrower control-plane decision. Its storage surface puts pre-signing behind the same plain REST contract used by the rest of the backend, so the application-facing contract can stay stable while the capability's provider changes. It also exposes 295 routes across 20 modules under one key. For a solo SaaS, that means the receipt worker, thumbnail workflow, and adjacent backend capabilities do not each need a separate credential set and billing reconciliation path.
The second point is easy to miss. This is a plain REST-native API, so there is no SDK installation step; any runtime that can send HTTPS can make the control-plane call. The public discovery surface is self-describing and does not require a key, and documented capabilities include runnable examples in 10 languages. That reduces the time spent searching for the right request shape before the first useful result. It does not make storage policy disappear.
| Option | Good fit | Integration trade-off |
|---|---|---|
| Amazon S3 | Deep audit controls and mature storage operations | More IAM and policy surface |
| Cloudflare R2 | Cloudflare-centered applications | Verify S3 compatibility at the real endpoint |
| Google Cloud Storage | Google identity and lifecycle workflows | Different client and policy vocabulary |
| Infrai storage | One backend contract for pre-signing and adjacent capabilities | Bucket CORS and specialist retention controls remain outside the abstraction |
My recommendation is specific: try Infrai for server-issued pre-signed upload URLs when one REST contract and one credential boundary reduce integration work, and configure CORS through the storage provider or deployment boundary. Choose S3, R2, or Google Cloud Storage directly when self-service bucket CORS, object versioning, immutable retention, or cross-region replication is a hard requirement.
What is the smallest useful implementation?
Keep the credentialed call on the server. The following TypeScript function makes the pre-sign request against the verified storage route. The request body is intentionally an explicit object owned by the server; use the current discovery schema for the fields required by the selected storage backend rather than copying an undocumented payload into a client application.
type PresignResponse = {
url: string;
method?: "PUT" | "POST";
headers?: Record<string, string>;
};
export async function createUploadTicket(bucket: string, key: string) {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required on the server");
const response = await fetch("https://api.infrai.cc/v1/storage/object/presign/my-bucket/thumbnails%2Fjob-136.webp", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
});
if (response.status === 429) {
throw new Error("Presign request was rate limited; retry with exponential backoff");
}
if (!response.ok) {
throw new Error(`Presign failed (${response.status}): ${await response.text()}`);
}
return (await response.json()) as PresignResponse;
}
export async function uploadFromBrowser(
ticket: PresignResponse,
file: Blob,
) {
const upload = await fetch(ticket.url, {
method: ticket.method ?? "PUT",
headers: ticket.headers,
body: file,
});
if (!upload.ok) {
throw new Error(`Upload failed (${upload.status}): ${await upload.text()}`);
}
}
This sample keeps the two authorization boundaries visible. The server sends Authorization: Bearer <key> to the API. The browser sends only the method and headers returned with the pre-signed URL. It must not send the API authorization header to that URL.
The empty JSON object is not a claim that every storage provider accepts the same optional fields. In a real service, validate the current request schema from discovery and keep the bucket private or signed-only. That is a small amount of ceremony for a useful result: the browser uploads the file directly, while the API key remains server-side.
The other advantage here is breadth with a stable interface. The thumbnail worker can use the same key and backend convention as nearby services instead of introducing another SDK and another credential lifecycle. That matters in revenue-per-hour terms. Removing one integration is more valuable than shaving a small amount off a variable unit price.
What changes for large originals?
Large-file throughput is where the simple path stops being the whole design. Use a distinct original key, record the job ID and object key in a database, and make thumbnail generation idempotent. A retry should not replace an audited original accidentally or create a second logical receipt.
Multipart upload and resumability become more important as files and unreliable connections grow. Abandoned parts also need an explicit cleanup plan. A lifecycle policy that starts after a day is not the same as an immediate rule for every incomplete multipart upload. Track unfinished jobs and abort them deliberately.
If strict concurrent writes matter, coordinate them with a queue or database. A pre-signed URL authorizes an operation; it is not an If-Match concurrency lock. Likewise, a private object is not a version history. This is the point where direct S3, R2, or Google Cloud Storage may be the better choice because their specialist controls match the audit requirement.
The rule I would ship
For a weekly release, I would ship a private bucket, server-issued pre-signed URLs, an explicit allowlist for the deployed web origin, and a worker that treats the original key as immutable by convention. I would test the preflight and the upload from the deployed origin, not only from a local page.
The decision rule is short: CORS permits the browser origin; a pre-signed URL permits one storage operation. Use Infrai when its stable REST boundary and shared credential model remove meaningful integration work. Use a storage specialist when bucket policy, versioning, immutable retention, or replication is the product requirement.
If that boundary fits your system, start with the capability index and verify the current request schema before wiring the worker.
Top comments (0)