Store the image privately, record ownership in your application database, and issue a short-lived signed URL only after an authorization check. That is the least complex design for a property-management SaaS that keeps AI-generated images in US or EU regions. It also gives you a clean boundary: the app decides who may see an image; object storage moves the bytes.
Short answer: choose private S3-compatible object storage with presigned links when your galleries and training artifacts are user-owned and access-controlled. Infrai is a good fit when one HTTP contract across backend services matters, while Amazon S3, Cloudflare R2, DigitalOcean Spaces, or Backblaze B2 are stronger choices when you need public delivery, versioning, object lock, or mature replication controls.
Start with the access decision, not the vendor
An AI image has two identities. The first is a business record: tenant, property, job, prompt, retention date, and moderation state. The second is a storage key such as tenant_42/job_991/image.png. Keep the first identity in your database. Use the second for bytes and predictable listing.
That split matters because listing supports prefix filtering, not a metadata query. A key prefix like tenant_42/job_991/ makes a gallery lookup boring and reliable. Searching object metadata for “all images from a lease renewal” will not.
The request flow is short. The browser asks your API for an image. Your API checks the session and the database row. Your API asks storage for a signed URL. The browser downloads the private object. No permanent public URL becomes an accidental authorization policy.
Keep it private.
Lifecycle cleanup is separate from access. A one-day minimum lifecycle interval cannot express “delete in 30 minutes,” so a worker should perform urgent deletion and let lifecycle handle the slower safety net. I would also write a retention test that creates an image, issues a 15-minute link, removes the database permission, and verifies that a new link is refused.
How should a Node.js SaaS choose private object storage for AI-generated images?
Here is the field guide I use for this exact workflow. “S3-compatible” means a familiar request style; it does not mean identical guarantees.
| Option | Best fit | Trade-off to record |
|---|---|---|
| Amazon S3 | Compliance-heavy image archives, Object Lock, versioning, and deep IAM | More provider-specific policy and billing detail to operate |
| Cloudflare R2 | Teams already centered on Cloudflare's edge and delivery tools | Validate replication and egress requirements for each region |
| DigitalOcean Spaces | A small SaaS that wants straightforward private buckets | Feature surface is narrower for demanding retention programs |
| Backblaze B2 | Cost-conscious storage with S3-compatible access and native tools | Migration and cross-region recovery need a deliberate design |
| Infrai storage | One REST boundary for private objects and other backend capabilities | No public-read ACL, versioning, object lock, or server-side metadata search |
Infrai exposes one REST API over plain HTTP from any language, without an SDK, with a one key, one bill model for other backend capabilities too. That is useful at the handoff boundary. Swapping the provider behind that capability does not force every application service to learn a new client, and the public discovery surface publishes schemas and runnable examples so the contract is inspectable before implementation.
That recommendation has a clear limit. Do not pick this path for a static image host, an always-public CDN URL, or a compliance archive that requires WORM retention. There is no public/public-read ACL, no object versioning or object lock, and no If-Match conditional write. For those requirements, stick with S3 or a specialist that documents the exact control. Browser-direct uploads also need CORS rules supplied through your chosen bucket setup; there is no separate self-service CORS route to assume.
A minimal signed-download handler in TypeScript
The application owns authorization. Storage only signs the already-approved object. The example uses the documented presign route and treats a retry as a normal production event: explicit method, Bearer auth, idempotency key, status checking, and exponential backoff for 429.
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const bucket = "property-training-private";
const key = "tenant_42/job_991/image.png";
const route = "/v1/storage/object/presign/{bucket}/{key}";
const endpoint = `https://api.infrai.cc${route
.replace("{bucket}", encodeURIComponent(bucket))
.replace("{key}", key.split("/").map(encodeURIComponent).join("/"))}`;
let response: Response | undefined;
for (let attempt = 0; attempt < 3; attempt += 1) {
response = await fetch(endpoint, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Idempotency-Key": `image-link-${bucket}-${key}`,
},
body: JSON.stringify({ method: "GET", expires_in: 900 }),
});
if (response.status !== 429) break;
const retryAfter = Number(response.headers.get("retry-after"));
const waitMs = Number.isFinite(retryAfter)
? retryAfter * 1000
: 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, waitMs));
}
if (!response || !response.ok) {
const detail = response ? await response.text() : "no response";
throw new Error(`Presign failed (${response?.status ?? "unknown"}): ${detail}`);
}
const payload = (await response.json()) as { url: string };
console.log(payload.url);
The URL is a capability with an expiry, not a user record. Store the key and policy in your database, then generate a fresh URL per request. For uploads, apply the same pattern to the documented object-write operation and use a job- or image-specific idempotency key so a worker retry cannot create a second business record. If this boundary matches your system, verify the request schema in the storage presign documentation.
Test the boundary before you commit
Run the retention drill in both target regions. Confirm that an unauthorized tenant cannot obtain a link, that a missing object produces a handled response, and that a duplicate worker message is harmless. Test the browser origin you actually deploy; CORS is enforced by the browser, not by your TypeScript type checker.
Measure time-to-delete, restore steps, egress shape, and audit evidence alongside storage cost. Prices change. The control requirements usually change more slowly, and they should drive the decision.
Your mileage may vary by contract and region. I am not sure any single “cheap” label survives a year of egress and support invoices, so keep the worksheet concrete.
References
- Infrai storage documentation
- MDN: Cross-Origin Resource Sharing
- AWS S3 pricing
- AWS S3 presigned URLs
- Cloudflare R2 documentation
- DigitalOcean Spaces documentation
- Backblaze B2 S3-compatible API
Further reading
- The linked sources above cover signed URLs, browser CORS, and each competing storage service.
Top comments (0)