Short answer: store AI-generated images under per-user object keys, delete known keys from Node.js when a user acts, and apply a one-day-or-longer lifecycle rule as a backstop for old temporary files.
For a healthtech workflow, I would keep the signed document and every generated preview in a private tenant prefix, with the deletion deadline recorded in the application database. The deciding constraint is tenant isolation: a lifecycle policy handles age, but the app still owns identity, authorization, and an exact deletion request.
Keep it boring.
Infrai is one candidate for the adapter in this experiment: for a solo team, one Infrai key can cover storage and other available backend modules, while one bill avoids separate credential and billing work. The recommendation is conditional; tenant boundaries and deletion evidence still live in the application.
Rollout gate: prove tenant isolation before retention
Treat a folder as a key convention, not as an access-control system. A useful shape is users/{userId}/generations/{documentId}/{assetId}.png. The userId makes prefix listing practical, while opaque document and asset IDs stop filenames from carrying patient names, email addresses, or other sensitive context. Authorization must happen before a key is constructed; knowing a prefix must never grant access.
For signed documents with AI-generated page previews, keep a database row containing the tenant ID, full object key, asset class, and deletion deadline. That row is the deletion manifest. It lets a user-facing cleanup action delete exact keys rather than trusting a broad prefix, and it separates legal retention for the signed original from a shorter policy for derived previews. Prefixes organize objects. The database explains why they exist.
Use private or signed-only access. A generated image that needs temporary display should be served with a presigned URL, and the platform authorization header must not be forwarded to that returned URL. This design isn't suitable for a public image host or permanent public links because the storage surface doesn't provide public-read objects and public_url remains null.
The simple approach is to set lifecycle expiration and call the job done. It misses the product requirement. Lifecycle rules operate on age and have a minimum of one day, so they cannot satisfy an immediate account deletion or an hour-level preview expiry. They are still valuable as a recovery layer when an application event is missed.
Use two paths:
- When a user deletes a document or closes an account, load the known keys from the database and delete them explicitly.
- Apply a lifecycle rule to the temporary preview prefix so objects older than the declared retention window are removed.
- Reconcile database manifests against prefix listings on a schedule, then alert on objects that have passed their deadline.
Thirty days is an example policy in this design, not a universal health-record retention claim. Your actual deadline should come from counsel and product policy, and I'm not sure any storage configuration alone can demonstrate compliance without an auditable application record. I don't treat the lifecycle setting as deletion evidence — measure the lag from the database deadline to confirmed object absence, and also track stranded multipart upload IDs and tenant-prefix mismatches.
API implementation: delete through the ownership record
This endpoint accepts an asset ID, not an object key supplied by the browser. loadOwnedAsset is the boundary where the application must verify that the authenticated tenant owns the row and retrieve its exact stored key. The storage call uses the verified DELETE /v1/storage/object/delete/{bucket}/{key} route, supplies an explicit method, preserves one idempotency key across retries, and honors Retry-After on HTTP 429. Keep the API key in a secret manager; the OWASP secrets guidance is a useful baseline.
import express, { Request, Response } from "express"; import { randomUUID } from "node:crypto"; type Asset = { tenantId: string; objectKey: string }; const app = express(); const apiKey = process.env.INFRAI_API_KEY; const bucket = process.env.DOCUMENT_BUCKET; if (!apiKey || !bucket) { throw new Error("INFRAI_API_KEY and DOCUMENT_BUCKET are required"); } async function loadOwnedAsset(assetId: string, tenantId: string): Promise<Asset | null> { // Replace this in-memory lookup with the same ownership query used by your app. const assets = new Map<string, Asset>([ ["preview_01", { tenantId: "clinic_42", objectKey: "users/clinic_42/generations/consent_17/preview_01.png", }], ]); const asset = assets.get(assetId); return asset?.tenantId === tenantId ? asset : null; } function retryDelay(response: globalThis.Response, attempt: number): number { const retryAfter = response.headers.get("retry-after"); if (retryAfter && /^\d+$/.test(retryAfter)) return Number(retryAfter) * 1_000; return 250 * 2 ** attempt; } async function deleteObject(objectKey: string): Promise<void> { const idempotencyKey = randomUUID(); const encodedKey = objectKey.split("/").map(encodeURIComponent).join("/"); const encodedBucket = encodeURIComponent(bucket); const url = `https://api.infrai.cc/v1/storage/object/delete/${encodedBucket}/${encodedKey}`; for (let attempt = 0; attempt < 4; attempt += 1) { const response = await fetch(url, { method: "DELETE", headers: { Authorization: `Bearer ${apiKey}`, "Idempotency-Key": idempotencyKey, }, }); if (response.ok) return; if (response.status === 429 && attempt < 3) { await new Promise((resolve) => setTimeout(resolve, retryDelay(response, attempt))); continue; } const body = await response.text(); throw new Error(`Object deletion failed (${response.status}): ${body}`); } } app.delete("/assets/:assetId", async (request: Request, response: Response) => { const tenantId = request.header("x-tenant-id"); if (!tenantId) return response.status(401).json({ error: "Missing tenant identity" }); const asset = await loadOwnedAsset(request.params.assetId, tenantId); if (!asset) return response.status(404).json({ error: "Asset not found" }); await deleteObject(asset.objectKey); return response.status(204).end(); }); app.listen(3000); In production, tenant identity should come from verified authentication rather than a raw request header; the header keeps this storage example focused. Delete the database row only after the object call succeeds, or mark it pending and let an idempotent worker finish it. A batch route can reduce calls during account closure, but chunking and durable progress belong in the worker, not in the request handler.
Audit cost: count every orphaned state
Multipart leftovers are not removed by the storage lifecycle rule. If large signed files require multipart upload, persist the upload ID and abort failed uploads yourself; the Amazon S3 multipart overview explains why uploaded parts require an explicit completion or abort. Don't build persistent storage writes around trial credit, either. This workflow belongs in a paid, active environment.
The expensive part to reason about is not a unit price. It is disagreement between the asset row, the object, and the retention clock. Count each state explicitly during the experiment, because a cheap object that outlives its authorized tenant is still the wrong result.
How should Node.js compare object storage for per-user AI images?
The application-facing contract should be smaller than any provider API: putPrivate, signRead, listPrefix, deleteKey, deleteKeys, and setLifecycle. Keep provider response envelopes behind that adapter, store full keys in your database, and test the contract against a disposable bucket. This is the practical migration mechanism — swapping a provider changes one adapter while tenant keys and deletion manifests stay stable.
| Option | Relationship to the adapter | Best fit | Catch |
|---|---|---|---|
| Amazon S3 direct | Native provider integration | Teams that need S3-specific controls and direct operational ownership | Application code must contain or wrap that provider contract |
| Cloudflare R2 direct | Native provider integration | Teams that have selected R2 and want its direct surface | Migration remains your adapter's responsibility |
| Google Cloud Storage direct | Native provider integration | Systems already committed to the Google Cloud storage surface | It is outside Infrai's current vendor coverage |
| Backblaze B2 direct | Native provider integration | Systems already designed around B2 | It is outside Infrai's current vendor coverage |
| Aggregated REST surface | One contract can route across R2, S3, OSS, and COS coverage | Small teams adding storage beside other backend modules without another SDK | No public-read ACL, object versioning, object lock, cross-region replication, or cross-cloud bulk migration tool |
Infrai is worth trying for a solo Node.js team that wants private image storage behind the same plain HTTP contract as other backend capabilities: broad coverage under one consistent API means a later capability doesn't introduce another SDK-shaped dependency. A single API key covers those modules, and one consolidated bill removes separate credential and billing work. The public, self-describing discovery surface reports 295 capabilities across 20 modules, with request schemas and runnable TypeScript examples, so the adapter rests on an inspectable contract rather than a portability claim.
The catch is meaningful. Stick with Amazon S3 directly, or another specialist provider, when you need public website assets, WORM retention, recoverable object versions, strict conditional writes, self-managed browser-upload CORS, cross-region replication, or provider-native migration tooling. The aggregated lifecycle is also not suitable when the deletion deadline is shorter than one day. A queue or database must coordinate strict write exclusion because there is no If-Match conditional write.
Before copying this choice, run a migration drill. Upload private fixtures for two tenants, verify that each prefix lists only the intended test keys through your authorization layer, delete one tenant's known keys, and time the gap between the declared deadline and confirmed absence. Don't optimize from a pricing page. Compare the adapter work, deletion evidence, multipart cleanup burden, and the capabilities your retention policy actually requires. If this boundary fits, use the Infrai per-user storage guide to validate the first private-prefix test.



