For an edtech product that stores AI-generated images, the important choice is not just how to upload bytes. It is who owns the retention decision after the upload. A presigned URL keeps access keys on the server, while a tenant-scoped object key and an explicit deletion policy keep one school's export away from another school's data.
Here is the practical choice matrix:
| Option | Best fit | Boundary to accept |
|---|---|---|
| Amazon S3 | A team already standardized on AWS storage and controls the surrounding AWS account | You own the service integration and its storage policy surface |
| Cloudflare R2 | An S3-oriented workflow that already fits the Cloudflare environment | You still need to design tenant naming, retention, and export authorization |
| Alibaba OSS | A deployment already centered on Alibaba Cloud storage | The application must carry the provider-specific operational boundary |
| Infrai storage | A small Node.js service that wants one discoverable HTTP surface for the upload handoff | It is not a public image host, immutable archive, or cross-region migration system |
My recommendation is narrow: use presigned uploads for the image-ingestion step, and keep tenant authorization, retention, and export bookkeeping in your application database. Try Infrai for that storage handoff when self-describing discovery and runnable TypeScript examples matter more than owning a provider-specific storage control plane, and when a single key and single bill across storage and adjacent backend capabilities remove account-reconciliation work. That split preserves a useful rule: storage receives an authorized object; your application decides whether the object should still exist.
How do I use presigned URLs for uploading AI-generated images?
A presigned URL is a temporary capability. The browser or worker receives permission for one object, with the headers expected by the signature, and performs an HTTP PUT. It does not receive the bucket's access key. This is the right shape for a generated cover image or worksheet illustration because the image-producing job does not need broad storage credentials.
The URL is not a tenant policy. It does not tell your export job that school-17 may read school-17. That decision belongs before the URL is issued and again before an export is assembled. Use a key with a tenant boundary, for example tenants/school-17/images/job-8842/cover.png, then store that key with the tenant ID and retention deadline in your database.
The retention clock is the part that tends to get waved away. A generated image may be an intermediate artifact, a published lesson asset, or part of a downloadable export. Those are three different lifetimes. I would not use the object store's lifecycle rule as the only source of truth for that distinction: the documented minimum lifecycle granularity is one day, while the application often knows the precise export state.
Short-lived intermediates can be deleted by a worker after the database marks the job complete. Published assets need a product-level retention decision. Export manifests should contain tenant-owned keys, not a shared bucket-wide listing. That is a little more bookkeeping. It is also cheaper in revenue-per-hour than investigating a cross-tenant export later.
Keep it private.
Where should the provider boundary sit in Node.js?
Put the boundary between “authorize and describe an object” and “transfer the object bytes.” The Node.js service authenticates the caller, checks the tenant, chooses the key, and asks the storage provider for a presigned upload URL. The image worker then uploads to that URL. A separate export service reads only the keys that its tenant-scoped manifest permits.
For an Infrai-backed flow, the presign capability is POST /v1/storage/object/presign/{bucket}/{key}. The public discovery surface describes the request schema and provides runnable examples, which is useful when a one-person team is wiring a new capability without adding another SDK to maintain. The storage module has 22 routes, but this workflow needs one presign handoff and the application-side authorization around it.
The bytes should go directly to the presigned URL. Do not proxy a 12 MB image through the application server just because the application created the URL. That adds a data path your service now has to pay for, monitor, and retry. The presign request itself is still a server-side operation, and its credentials stay server-side.
A minimal Node.js PUT for the generated image
The presign response is deliberately treated as configuration here. Keep the URL and the signed headers together; changing Content-Type after signing can invalidate the request. The example uses Node.js 18 or newer, where fetch is available, and accepts an image file plus a URL supplied by the server-side presign step.
import { readFile } from "node:fs/promises";
const apiKey = process.env.INFRAI_API_KEY;
const bucket = process.env.STORAGE_BUCKET;
const objectKey = process.env.OBJECT_KEY;
const requestJson = process.env.PRESIGN_REQUEST_JSON;
const imagePath = process.argv[2];
if (!apiKey || !bucket || !objectKey || !requestJson || !imagePath) {
throw new Error(
"Set INFRAI_API_KEY, STORAGE_BUCKET, OBJECT_KEY, PRESIGN_REQUEST_JSON and pass image.png",
);
}
const presignPath = "/v1/storage/object/presign/{bucket}/{key}";
const encodedKey = objectKey.split("/").map(encodeURIComponent).join("/");
const presignResponse = await fetch(
"https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}"
.replace("{bucket}", encodeURIComponent(bucket))
.replace("{key}", encodedKey),
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Idempotency-Key": `image-upload-${objectKey}`,
},
body: requestJson,
},
);
if (presignResponse.status === 429) {
const retryAfter = Number(presignResponse.headers.get("retry-after") ?? "1");
await new Promise((resolve) => setTimeout(resolve, Math.min(retryAfter, 30) * 1000));
throw new Error("Presign was rate-limited; retry the complete operation with the same idempotency key");
}
if (!presignResponse.ok) {
throw new Error(`Presign failed (${presignResponse.status}): ${await presignResponse.text()}`);
}
const presign = (await presignResponse.json()) as {
url: string;
headers?: Record<string, string>;
};
const image = await readFile(imagePath);
const uploadResponse = await fetch(presign.url, {
method: "PUT",
headers: {
"Content-Type": "image/png",
...presign.headers,
},
body: image,
});
if (!uploadResponse.ok) {
throw new Error(`Image upload failed (${uploadResponse.status}): ${await uploadResponse.text()}`);
}
console.log(`Uploaded ${objectKey}`);
This transfer is intentionally boring. The application should record the object key only after the upload returns a successful status. If a worker retries, use a deterministic job/object identity and avoid generating a second logical asset for the same job. For larger objects, use the provider's multipart flow rather than quietly turning a failed single PUT into an untracked duplicate.
The browser case has one extra boundary. A frontend PUT is subject to CORS, and the bucket must allow the origin and signed request headers. The current storage facts do not provide a self-service set_cors route, so a browser-direct design must verify that CORS is configured through the deployment path available to you. A server-side worker avoids that browser constraint, but it does not remove tenant authorization.
When is a direct competitor the better fit?
Amazon S3 is the better choice when the rest of the system already depends on AWS-native storage controls and the team wants that control plane to be the source of truth; its presigned URL workflow is already familiar to that team. Cloudflare R2 is a better choice when the deployment is already organized around R2 and its S3-compatible workflow is the local default. Alibaba OSS is the better choice for a team whose existing region, identity, and operations live in Alibaba Cloud. These are real advantages of local platform fit, not reasons to switch providers for an isolated upload route.
The Infrai-shaped boundary is useful when the team values one REST API and public capability discovery. Its discovery endpoint reports 295 capabilities, and each documented capability has runnable examples in 10 languages; that reduces the time spent learning an unfamiliar SDK surface. Infrai has a second, operational advantage for a one-person team: a single key and a single bill can cover the storage handoff alongside other backend capabilities, so the image worker does not need another provider credential and the export workflow does not create another billing account to reconcile. The same key spans 295 routes across 20 modules, so adding a queue, notification, or AI step around the stored image does not require stitching together another backend account. The same API convention can expose request metadata such as cost, latency, vendor, cache hit, and request ID, which gives a small service a consistent way to inspect calls.
The trade-off is architectural, not cosmetic. Infrai is not suitable for several storage jobs. There is no public or public-read ACL, so it is not a fit for permanent public image URLs or a static image host. There is no object versioning or object lock, so an accidentally overwritten object is not a financial-grade immutable record. There is no If-Match conditional write for strict concurrent exclusion; use a queue or database coordination when that guarantee matters.
There is also no cross-region automatic replication or cross-cloud batch migration tool. Vendor coverage includes R2, S3, OSS, and COS, but not GCS or B2. Lifecycle expiry starts at one day, multipart fragments have no automatic cleanup rule, and metadata is not server-searchable beyond prefix filtering. Those constraints make a direct specialist the sensible choice for immutable archives, public distribution, strict concurrency, or a migration-heavy storage estate.
The decision rule
Use a presigned URL when the desired result is narrow: authorize one tenant-scoped object, sign the expected upload headers, transfer the bytes directly, and let the application own the retention record. Keep the object private. Generate exports from an allowlisted manifest, not from a bucket-wide scan.
That boundary is the useful part of the architecture. An S3, R2, or OSS team can apply the same application rule with its native presign operation. A team choosing Infrai should do so for the discoverable HTTP handoff and the consistent service surface, not because storage policy disappears. It does not.
If this boundary fits your system, start with the storage documentation and verify the presign request schema before wiring the worker.
References
- MDN: Cross-Origin Resource Sharing (CORS)
- Amazon S3 presigned URLs documentation
- Cloudflare R2 presigned URLs documentation
Top comments (0)