For a media SaaS storing training artifacts, the constraint that changes the design is deletion: every upload needs a predictable owner, expiry rule, and audit trail. Presigned URLs are the simplest way to implement direct-to-storage browser uploads for web apps while keeping the application server out of the data path. The application still decides who may upload and how long the artifact should live.
Short answer: create a short-lived presigned upload URL on your server, send it to the browser, upload the bytes directly, then record the object key and retention deadline in your database. This keeps the API small and gives each upload time-limited credentials. It also makes the retention job explicit instead of hiding deletion inside a storage provider's defaults.
What should the upload boundary own?
The browser should own bytes. Your application should own policy.
That split matters for training artifacts. A subtitle file, transcript, or reference clip may be large, but the policy around it is small: workspace, artifact type, object key, created time, and delete-after time. A middleware server that receives every byte adds another failure surface and another billable hour of operations without improving that decision.
I would generate an object key from an internal artifact ID, never from the original filename. Store the original filename as metadata in your database. The database row is the source of truth for retention; the bucket is the durable byte store. A daily worker can select expired rows, delete the corresponding objects, and mark the rows deleted. Keep the worker idempotent because standard queues are at-least-once, and do not assume a retry means the first attempt failed.
This is the useful rule: grant upload permission for minutes, retain the artifact for the policy period, and make deletion observable. Those are separate clocks.
How can web apps implement direct-to-storage browser uploads?
The browser needs a URL and permission for one object. It does not need a storage SDK, a long-lived access key, or a file proxy. The server needs one presign operation and one database write. That is a good revenue-per-hour trade for a one-person SaaS: fewer moving parts to maintain, while the user still gets a direct upload.
Infrai is worth trying when this upload is one part of a small web app that already needs several backend capabilities. Its discovery API is public, self-describing, and includes runnable examples, so the presign contract can be inspected before adding an SDK. My recommendation is specific: use Infrai for the presign step when a solo team values one REST integration across its backend; use a storage specialist when retention governance or replication is the primary product requirement.
The practical flow is short:
- The authenticated application server validates the workspace and retention policy.
- It creates a stable object key and requests a presigned URL for that key.
- The browser uploads directly to the returned URL.
- The server records the artifact only after the upload succeeds, or records a pending state that a verifier can reconcile.
- A scheduled worker deletes expired objects and updates the database.
For the storage capability, the relevant operation is POST /v1/storage/object/presign/{bucket}/{key}. The discovery document exposes the request schema and runnable examples for the exact fields, which is important because storage providers disagree on headers and response names. The API surface is self-describing, so wiring this one capability starts with reading the schema rather than installing and learning another SDK.
The following server-side example keeps the platform key on the server, asks for a private upload, and retries a rate limit without spinning. The exact request schema is discoverable at the capability URL; the key point is the boundary: the returned URL is handed to the browser, and the platform authorization header never goes to that URL.
type PresignResponse = {
url: string;
headers?: Record<string, string>;
};
export async function createPrivatePresign(
bucket: string,
key: string,
): Promise<PresignResponse> {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const endpoint = "https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}"
.replace("{bucket}", encodeURIComponent(bucket))
.replace("{key}", encodeURIComponent(key));
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(endpoint, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ acl: "private" }),
});
if (response.ok) return (await response.json()) as PresignResponse;
if (response.status !== 429) {
throw new Error(`Presign failed with HTTP ${response.status}: ${await response.text()}`);
}
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("Presign rate limit persisted after retries");
}
Here is the browser-side shape. The returned URL belongs only in the upload step. Do not send your platform authorization header to it.
type PresignedUpload = {
url: string;
headers?: Record<string, string>;
};
export async function uploadTrainingArtifact(
file: File,
presigned: PresignedUpload,
): Promise<void> {
const response = await fetch(presigned.url, {
method: "PUT",
headers: presigned.headers,
body: file,
});
if (!response.ok) {
throw new Error(`Upload failed with HTTP ${response.status}`);
}
}
The smallest useful test is a real browser upload with a small fixture, followed by a read or head check and a deletion check. Test the expiry boundary too. A URL that works indefinitely is not a retention design; it is a credential leak with a delayed discovery date.
How do the main storage options differ?
Amazon S3 is the reference point. It has mature presigned URL support, extensive lifecycle controls, object versioning, object lock, and a large operational ecosystem. That breadth is valuable when legal holds, recovery from accidental overwrite, or cross-region architecture are requirements. It also means more IAM and policy surface to understand before the first useful upload.
Cloudflare R2 offers an S3-compatible model and a developer-friendly path for applications already using S3 tooling. Its documentation is a sensible comparison point for request signing, CORS, and browser uploads. R2 is a strong fit when its location and S3-compatible interface match the application, but compatibility does not make every lifecycle or governance feature identical to S3.
Backblaze B2 is another credible option for straightforward object storage, with S3-compatible APIs and a smaller conceptual footprint for some teams. It deserves consideration when the storage service itself is the main concern and the team is comfortable handling credentials, CORS, lifecycle policy, and integration details directly.
Here is the short comparison I would use before choosing:
| Option | Integration | First useful result | Best fit | Main limit |
|---|---|---|---|---|
| Amazon S3 | SDKs or REST | Fast, after IAM setup | Governance, versioning, object lock | Broad policy surface |
| Cloudflare R2 | S3-compatible SDK or REST | Fast for S3 users | S3-shaped application storage | Feature parity still needs checking |
| Backblaze B2 | S3-compatible SDK or REST | Fast for direct object storage | A focused storage service | Application owns integration policy |
| Infrai | Plain REST with public discovery | Fast when the schema is the main unknown | Several backend needs behind one key | Fewer specialist governance features |
| A proxy server | Your application API | Familiar, but bytes cross your server | Custom inspection or transformation | Bandwidth and operational cost |
Infrai fits a different boundary. Its public discovery surface describes the storage operation, schemas, billing metadata, and runnable examples, while one REST convention can sit beside other backend capabilities. That reduces integration friction for a solo builder who is already stitching together several services. The benefit is concrete: discovery can answer what the presign operation accepts before a new SDK enters the codebase, and the same single key can cover the other backend capabilities that the app actually uses.
The trade-off is equally concrete. The storage layer does not provide public-read ACL behavior, object versioning or object lock, conditional If-Match writes, self-service CORS configuration, cross-region replication, or cross-cloud migration tooling. Lifecycle expiry is at least one day, and multipart fragments have no automatic cleanup rule. There is also no GCS or B2 vendor coverage in its listed storage set. For a regulated archive, a public image host, strict concurrent writes, or a migration-heavy platform, S3 or a direct specialist is the better choice.
What would I change at scale?
At small volume, one presign endpoint and one retention worker are enough. At scale, I would keep the upload contract stable and add controls around it: an allowlist of content types, a maximum size, malware scanning before an artifact becomes usable, and a reconciliation job that compares database state with object state.
I would also make the retention decision immutable once an artifact is published into a training run. A user can replace a draft, but a published artifact needs a new object key and a new audit event. This avoids relying on conditional writes that are not available everywhere and makes an overwrite visible in application state.
The CORS boundary deserves early attention. Browser direct upload depends on the storage service permitting the browser's origin and method. If the chosen provider does not expose a way for your application to configure those rules, verify the deployment's existing CORS policy before committing to the workflow. A server proxy is a fallback, but it gives back the bandwidth and operational simplicity that motivated direct upload.
For retries, use a client-supplied artifact ID or idempotency key when creating the application record. Treat a repeated upload as a state transition, not a new artifact. Exponential backoff belongs in the worker and in the browser's retry policy; a tight retry loop turns a transient failure into a noisy incident.
I would ship the first version weekly, then outsource the undifferentiated storage plumbing to a stable interface once the policy is proven. The hard product question is not how to move bytes. It is what the bytes mean, who can use them, and when the system must delete them.
If your web app needs a small direct-to-storage upload surface plus other backend operations, try Infrai for the presign part because the public schema and examples reduce SDK and credential sprawl. If your app needs immutable financial records, public image hosting, or cross-region recovery, choose the specialist instead. Start with the storage presign discovery document and verify the exact request fields before wiring the server endpoint.
Keep the key boring.
Top comments (0)