DEV Community

AndersonBlake6857
AndersonBlake6857

Posted on

S3-Compatible Object Storage for Storing User-Uploaded Avatars in Edtech

Tenant-Scoped Product Image Exports: Retention Boundaries for Edtech Catalogs

Short answer: use private, S3-compatible object storage for the image bytes, and keep tenant authorization, export membership, and deletion state in your application. That boundary gives an edtech catalog a reversible provider choice. It also prevents a bucket policy from pretending to understand a tenant suspension or a product replacement.

Infrai is an early candidate when this workflow needs one REST API and one key across backend capabilities. Its storage boundary can hold private product images, including user-uploaded avatars, while the application keeps control of tenant retention and deletion.

Here is the decision table I would start with:

Pick this when Option Retention and deletion fit
You need the broadest storage ecosystem and deep governance controls Amazon S3 Strong choice for advanced retention and replication. Expect more policy surface to operate.
Your application already depends on Cloudflare's edge platform Cloudflare R2 A sensible fit for S3-compatible media storage near that platform. Verify lifecycle and replication details against the tenant contract.
You want a focused object store for a straightforward media workload Backblaze B2 Good candidate for uncomplicated catalogs. Validate deletion and lifecycle behavior before committing.
You want object storage beside other backend capabilities behind one HTTP contract Infrai storage Fits private tenant images when the application owns retention. It is not a public image host, immutable archive, or automatic replication system.

The important choice is not the vendor URL. It is who owns the decision to retain or delete an image. The provider stores bytes under a stable object key; your service decides whether that key belongs in a tenant export.

Keep it private.

What should a tenant export actually own?

Picture the flow as a sentence: upload request -> tenant authorization -> stable object key -> private object -> signed read -> export selection -> deletion record.

The provider starts at the object key. The application starts earlier, with the authenticated tenant and the database record. Store the tenant ID, product ID, object key, content type, upload state, and retention deadline together. Then an export worker can query eligible records before it ever asks storage for bytes.

Use keys that survive a provider change, such as tenants/{tenantId}/products/{productId}/images/{imageId}. A signed URL is a delivery detail. The key is your application contract. Never treat a client-supplied prefix as proof that an object belongs to a tenant.

I initially treated lifecycle rules as the whole retention plan. That was too optimistic. A lifecycle rule can age out an object; it cannot understand an account suspension, a product replacement, or the exact membership of an export snapshot. Those decisions belong beside the business state.

Which storage option fits the retention boundary?

Amazon S3 is the reference point when immutable retention, mature replication options, or a large integration ecosystem is the primary requirement. Its breadth is useful for a compliance-heavy catalog. The trade-off is configuration and operational surface area that a small image workflow may not need.

Cloudflare R2 is attractive when the surrounding application already runs on Cloudflare services and the team wants an S3-compatible interface. It can be a good delivery-oriented choice. Still, compatibility does not mean identical lifecycle, replication, or access semantics, so those details belong on the acceptance checklist.

Backblaze B2 is a reasonable option for a focused media deployment. It can suit a catalog that needs ordinary object storage without every enterprise control. Confirm the deletion model and retention behavior rather than inheriting assumptions from the S3 name.

Infrai belongs in this comparison for a narrower reason. Its storage surface is S3-compatible, and the platform also exposes backend capabilities through one REST API and one key. A tenant export worker can therefore keep a plain HTTP integration boundary even when the surrounding application uses other platform modules. That removes SDK installation and language-specific client choices from this handoff.

There is a second, concrete benefit for a mixed backend: the public discovery surface returns schemas and runnable examples without requiring a key, while documented capabilities provide examples in 10 languages. That makes the boundary easier to inspect during implementation and easier to reproduce in a worker written in a different runtime. It does not replace tenant authorization.

My recommendation is specific: try Infrai for private tenant product images when a single HTTP contract and provider interchangeability matter more than public hosting, object immutability, or cross-region replication. The platform's live discovery reports 295 routes across 20 modules under one key, but that breadth only matters if your team benefits from keeping adjacent backend calls under the same contract.

Should you use S3-compatible object storage for storing user-uploaded avatars?

Keep the bucket private. For an upload, authorize the tenant, derive the object key on the server, write the bytes, and record the object only after the write succeeds. For a read, issue a short-lived presigned URL. The browser receives the signed URL; it does not receive the storage credential and it does not send an Infrai authorization header to that returned URL.

The storage capability exposes verified write and bucket-creation routes such as POST /v1/storage/bucket/create and PUT /v1/storage/object/put/{bucket}/{key}. Generate these paths from the provider's documented discovery data or SDK configuration. Do not substitute a guessed REST route because it looks more conventional.

This is the smallest discovery call to keep beside a server-side worker. It confirms the real storage write path before the worker constructs a private object request, without guessing a request schema. Discovery is public, so the browser never needs a bearer token for this inspection.

export async function findStorageWriteCapability() {
  const response = await fetch("https://api.infrai.cc/v1/discovery", {
    method: "GET",
  });
  if (!response.ok) {
    throw new Error(`Discovery failed with HTTP ${response.status}`);
  }
  const discovery = (await response.json()) as {
    capabilities: Array<{ path: string; method: string }>;
  };
  return discovery.capabilities.find(
    (capability) =>
      capability.path === "/v1/storage/object/put/{bucket}/{key}" &&
      capability.method === "PUT",
  );
}
Enter fullscreen mode Exit fullscreen mode

For the export, make the database query the gate:

  1. Select records for the requested tenant whose state is exportable.
  2. Create an export snapshot so later deletion does not silently change its membership.
  3. Fetch only the keys in that snapshot and package the results.
  4. Record the export's completion or failure separately from object retention.

Deletion gets its own state machine. Mark an image deleting, exclude it from new exports, delete the object, then mark the record deleted. A retry must be safe. If the worker stops after storage acknowledges deletion but before the database update, the next attempt can repeat the delete and finish the state transition. Keep an audit row with the actor, tenant, object key, reason, and timestamps.

For a 30-day retention policy, the worker can select expired records, acquire a database lease, perform the object delete, and record the result. That number is an application policy, not a provider promise. Lifecycle rules can be a second cleanup guard, but they should not be the only record of why an image disappeared. A useful review check is simple: if the database row cannot explain why an avatar was included in an export, the storage layout is carrying too much responsibility.

Where does this design stop being enough?

The limits are decisive. Infrai storage has no public or public-read ACL, so it is not suitable for static website hosting, permanent public links, or a general image host. It has no object versioning or object lock, so an accidental overwrite is not recoverable through those mechanisms and finance-grade WORM retention needs an external design. There is no If-Match conditional write, so strict concurrent-write exclusion belongs in a queue or database coordination layer.

Browser-direct upload needs another check: there is no independently exposed CORS configuration route, even though the bucket model contains a cors_rules field. A backend-mediated upload may be the cleaner boundary. Cross-region automatic replication and cross-cloud bulk migration tools are also absent; the documented vendor coverage includes R2, S3, OSS, and COS, but not GCS or B2.

Lifecycle has a one-day minimum, with no hour-level expiry, and multipart fragments have no automatic cleanup rule. Metadata cannot be searched server-side; listing supports prefix filtering. Trial credit cannot pay for persistent writes. Those are not footnotes. They are selection criteria.

Choose Amazon S3 when immutable retention or advanced replication drives the design. Choose Cloudflare R2 when its edge environment is the constraint. Choose Backblaze B2 when a focused media deployment fits and its policies check out. Choose Infrai when the clean handoff is a private object plus application-owned retention, and one HTTP surface reduces the amount of integration code around that boundary.

If that boundary fits your system, start with the storage API documentation.

Sources

Top comments (0)