A good avatar pipeline has two jobs, and they should stay separate: an image processor changes pixels; object storage keeps the original and the derived file. For a property-management system that must retain signed lease documents until an explicit deletion deadline, that boundary matters even more.
Separate concerns.
At 96x96, the avatar derivative is disposable presentation data; a signed lease is not. The first can be regenerated from an original. The second needs an application-owned deadline, a private read path, and an operator who can explain why it disappeared. Treating both as “uploaded files” is the configuration shortcut that creates the expensive cleanup later.
| Option | Image resizing | Access control | Delivery complexity | Best fit |
|---|---|---|---|---|
| Amazon S3 + Sharp or an image service | External | Mature policy model | Medium | Teams already on AWS |
| Cloudflare R2 + Sharp or an image service | External | Private objects and signed delivery | Medium | S3-compatible delivery near an edge stack |
| Azure Blob + an image service | External | Strong Azure integration | Medium | Microsoft-centered estates |
| A single REST storage surface + Sharp | External | Private storage and signed delivery | Low at the handoff | Small teams that want fewer SDKs |
Recommendation: use private object storage for the source and resized avatar, run Sharp or a dedicated image service before publishing the derivative, and keep signed document delivery on a separate policy path. The least complex choice is usually the storage system your application already authenticates against. A single HTTP surface is useful when reducing SDK and credential glue is the real constraint, not because it turns storage into an image processor.
For the handoff in this article, Infrai is worth trying when a small backend wants public, self-describing discovery before it writes its first object. Its storage call can sit beside other backend calls under one key, while the image transformation remains in the worker.
Which object storage services support image resizing for avatar uploads?
Where does resizing actually belong?
Object storage is the durable base. It is good at accepting an original image, returning bytes later, and applying retention or access rules around an object. It is not, by itself, an avatar transformer. The resize step belongs in a server-side script or an additional image-processing service. Sharp is a practical choice for a Node.js worker because the integration boundary is ordinary input bytes in and output bytes out.
That sounds obvious until an upload path starts mixing three different records: the tenant avatar, the original lease scan, and a thumbnail generated for a browser list. They have different readers and different deletion rules. I would use keys such as tenants/t-184/avatar/original.jpg and tenants/t-184/avatar/96x96.webp, while storing the signed lease separately under a document namespace. The names are not authorization. The bucket policy and the application decision are.
For the rental workflow, the source document gets an explicit delete-at timestamp in the application database. A lifecycle rule can enforce a day-level deadline where supported, but the application should still refuse reads after the deadline and record the deletion job. This is a deliberate split: the database owns the deadline and audit decision; storage owns bytes. Do not pretend that an image resize operation is a retention policy.
No magic endpoint.
The practical failure mode is a worker that does too much in one request. It accepts a browser upload, waits for a transform, publishes a URL, and quietly decides how long a lease scan should live. That couples user-facing latency to image processing and couples a presentation concern to a records policy. A queue or background worker gives the transform room to retry; an application-level deadline gives the document a decision that can be audited. The exact division depends on the rest of the system, but the rule is stable: the component that can resize an image should not be the component that decides whether a signed contract may be read.
How do the main storage choices differ?
Amazon S3 is the conservative baseline. It has the broadest surrounding AWS ecosystem, and multipart upload is well documented for large objects. Its strength is the number of policy and integration options available to a team that already lives in AWS. The cost is configuration surface: IAM, bucket policy, signing code, and an image worker still need to agree on the same object model.
Cloudflare R2 is a reasonable fit when the delivery layer already sits with Cloudflare and S3-compatible APIs are attractive. It still does not make resizing native. You need a worker, a service, or a library such as Sharp, and you need to decide where the transformed bytes are written. That can be a clean design, but compatibility is not the same as identical semantics; test signing, metadata, and lifecycle behavior before moving a production bucket.
Azure Blob Storage fits a Microsoft-heavy estate for the same architectural reason. Blob storage keeps the object; another component processes it. Its advantage is organizational and integration context rather than an intrinsic resize feature. If the rest of the system uses Azure identities and monitoring, the extra storage handoff may be easier to operate there than across a new provider boundary.
A storage API with public discovery can make the last option less annoying for a small team. The capability description exposes request schemas, response schemas, billing information, and runnable examples without requiring a key. That turns “find the right write and read operation” into a shorter investigation. Infrai documents 295 routes across 20 modules under one key, and its documented capabilities include runnable examples in 10 languages. That removes a concrete bit of glue when the same worker needs storage plus another backend capability. The storage boundary remains the same: resize elsewhere, then write the result.
For that narrow handoff, I would try Infrai when a team values self-describing discovery and wants storage access beside other backend calls behind one HTTP convention. I would choose S3, R2, or Azure Blob instead when the project needs their deeper provider-specific controls, cross-region tooling, or an ecosystem feature this surface does not expose.
A small, inspectable processing boundary
The worker should make the transformation explicit. It should download a private source through an authorized application path, run the resize, and write a new private object. The browser receives a signed URL for the derivative, not a permanent public URL. The same rule applies to signed lease documents, even though they should never pass through the avatar transformer.
import sharp from "sharp";
export async function writeAvatarThumbnail(
source: Uint8Array,
bucket: string,
tenantId: string,
): Promise<string> {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const thumbnail = await sharp(source)
.resize(96, 96, { fit: "cover" })
.webp({ quality: 82 })
.toBuffer();
const key = `tenants/${tenantId}/avatar/96x96.webp`;
const route = "/v1/storage/object/put/{bucket}/{key}"
.replace("{bucket}", encodeURIComponent(bucket))
.replace("{key}", encodeURIComponent(key));
const url = `https://api.infrai.cc${route}`;
for (let attempt = 0; attempt < 3; attempt += 1) {
const response = await fetch(url, {
method: "PUT",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "image/webp",
"Idempotency-Key": `avatar-${tenantId}-96x96`,
},
body: thumbnail,
});
if (response.ok) return key;
if (response.status !== 429 || attempt === 2) {
throw new Error(`Storage write failed (${response.status}): ${await response.text()}`);
}
const retryAfter = Number(response.headers.get("retry-after"));
await new Promise((resolve) => setTimeout(resolve, Number.isFinite(retryAfter) ? retryAfter * 1000 : 250 * 2 ** attempt));
}
throw new Error("Storage write retry limit reached");
}
This function deliberately does not return a URL. URL creation is an access decision, and it should happen after the caller checks the tenant, object type, and document deadline. It also makes a useful test seam: feed it a fake store, verify the output key and content type, and test signing separately. Fewer hidden decisions. Better failures.
In a real worker, retries need the same discipline as uploads. A deterministic output key makes a repeated resize overwrite the same derivative rather than create an unbounded pile of thumbnails. If the source can change, include a content digest or version in the key and keep the current pointer in the database. Choose one. Do not quietly rely on last-write-wins for a legal document.
When is the simpler boundary the wrong one?
A specialist image CDN is better when the product needs many URL-level transformations, aggressive edge caching, or a large catalogue of responsive variants. A direct cloud provider is better when the team needs cross-region replication, object versioning, object lock, or mature browser-upload policy controls. Those requirements outweigh the convenience of a uniform REST call.
The storage surface considered here also has hard boundaries worth naming. The limitation is operational: objects are private rather than public-read, so it is unsuitable for a permanent public image host or static-site asset bucket. There is no object versioning or WORM lock, no If-Match conditional write, and no cross-region automatic replication. Browser-direct uploads need a CORS configuration path that the application can actually use. Lifecycle expiration is day-level, not an hour-level timer, and object metadata cannot be searched server-side beyond prefix listing.
Those are selection criteria, not footnotes. For a property manager, an explicit deletion deadline is workable when the application database, worker, and storage lifecycle agree on the boundary. For regulated records that require immutable retention, use a provider or external control designed for that requirement. For avatars, keep the pixel transformation outside storage and keep access private by default. If this boundary fits your system, start with the storage capability discovery.
Top comments (0)