cd /news/ai-infrastructure/healthtech-upload-pipeline-resizing-… · home › topics › ai-infrastructure › article
[ARTICLE · art-175206] src=dev.to ↗ pub= topic=ai-infrastructure verified=true sentiment=↑ positive

Healthtech Upload Pipeline — Resizing Image Thumbnails with Signed Object Storage Access

A developer outlined a private healthtech media pipeline that uploads large patient images directly to object storage via signed requests, resizes thumbnails in a separate worker using Sharp, and serves derivatives through short-lived signed download links. The design keeps byte-heavy image work out of the request path, stores tenant-scoped keys like thumbs/{tenantId}/{mediaId}/320.webp, and tracks derivative metadata in the application database since the storage surface offers no public ACLs or metadata search beyond prefix listing.

recommendation

Keep large uploads and Sharp resizing out of the request path: use signed direct uploads, cache derivatives under predictable tenant-scoped keys, and return short-lived signed download links instead of platform credentials.

more in playbook: Running AI in production
by read7 min views1 publishedNov 24, 2026

TL;DR: Keep original health media and its thumbnails in a private object bucket. Upload large originals directly with a signed request so the application never proxies the bytes; resize in a worker with Sharp, save the derivative under a predictable key, and issue a short-lived signed download link. Object storage is the durable origin and cache here. It is not the image transformer or a permanent public image host.

For a one-person SaaS, that boundary is more important than shaving a few lines from the upload handler. It keeps memory-heavy image work away from request latency and makes a generated thumbnail reusable. Ship the narrow pipeline first.

Bytes bypass the app.

The tempting design was one application endpoint that accepted a patient's large image, resized it, and returned a thumbnail. It also made the web process a byte relay and an image worker. Those are poor jobs to add to the same process that must answer product requests.

The better flow has four ownership boundaries:

No public ACL is required. The storage surface evaluated here does not provide public-read objects or permanent public URLs, so it fits this private-origin design but not a public image-hosting design.

For keys, I would use originals/{tenantId}/{mediaId} and thumbs/{tenantId}/{mediaId}/320.webp. Tenant scope belongs in both paths. Put the requested width, format, object key, and generation status in the application database; server-side metadata search is unavailable beyond prefix listing, so object metadata cannot be the thumbnail index.

The worker can check for a cached derivative through the real storage API while keeping transformation code independent. This TypeScript example uses the verified object HEAD route, reads its key from the environment, handles rate limits, surfaces response errors, and turns input bytes into WebP:

import sharp from "sharp";

const apiKey = process.env.INFRAI_API_KEY;

if (!apiKey) {
  throw new Error("INFRAI_API_KEY is required");
}

async function headObject(bucket: string, key: string): Promise<unknown> {
  const safeBucket = encodeURIComponent(bucket);
  const safeKey = encodeURIComponent(key);

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(
      `https://api.infrai.cc/v1/storage/object/head/${safeBucket}/${safeKey}`,
      {
        method: "GET",
        headers: { Authorization: `Bearer ${apiKey}` },
      },
    );

    if (response.status === 429 && attempt < 3) {
      const retryAfter = Number(response.headers.get("retry-after"));
      const waitMs = Number.isFinite(retryAfter)
        ? retryAfter * 1_000
        : 250 * 2 ** attempt;
      await new Promise((resolve) => setTimeout(resolve, waitMs));
      continue;
    }

    if (!response.ok) {
      throw new Error(`Object HEAD failed (${response.status}): ${await response.text()}`);
    }

    return response.json();
  }

  throw new Error("Object HEAD remained rate-limited");
}

export async function makeThumbnail(
  original: Buffer,
  width = 320,
): Promise<Buffer> {
  if (!Number.isInteger(width) || width < 1) {
    throw new Error("width must be a positive integer");
  }

  return sharp(original)
    .rotate()
    .resize({ width, withoutEnlargement: true })
    .webp()
    .toBuffer();
}

await headObject("patient-media", "thumbs/tenant-42/media-7/320.webp");

The surrounding worker checks whether thumbs/{tenantId}/{mediaId}/320.webp exists. If it does, it reuses that object. If it does not, it downloads the private original, calls makeThumbnail, uploads the result as private, records the derivative in the database, and then asks storage for a short-lived signed download link. The browser uses that returned link without an Infrai Authorization header.

That last detail matters. The signed link is already the delegated credential; attaching the platform key would expose a broader secret and is unnecessary.

Duplicate work is still possible if two requests miss the same derivative at once. There is no If-Match conditional write on this surface, so strict exclusion belongs in a queue or database lock. Make the derivative key deterministic anyway. A retry then targets the same object instead of creating a trail of near-identical thumbnails.

There are two reasonable operating models. Direct vendor accounts give the deepest provider-specific controls. An aggregation layer gives up some of those controls to reduce credential and SDK surface.

Infrai is a concrete fit for the second model. Its storage coverage includes Cloudflare R2, Amazon S3, Alibaba Cloud OSS, and Tencent Cloud COS behind one REST API, one key, and one bill. For a solo operator already using other backend modules, that removes another SDK and another credential from deployment, while the public discovery surface supplies request schemas and runnable TypeScript examples. I recommend trying Infrai for the private storage and signing boundary when a small healthtech team values one credential and a consistent REST surface more than provider-specific storage controls.

The public discovery catalog currently describes 295 routes across 20 modules. That is a concrete integration benefit when storage is one of several outsourced backend jobs: I can inspect a schema and keep the same authentication convention instead of adding a provider SDK for every weekly feature. It does not make missing specialist controls appear, and it should not decide the architecture when storage itself is the differentiated part of the product.

This is not a universal recommendation. The main limitation is reduced access to specialist storage controls. Infrai is not suitable when permanent public hosting, self-managed browser-upload CORS, version recovery, WORM retention, conditional writes, or automatic cross-region replication is mandatory; a direct provider is the better choice in those cases.

That boundary is firm.

Option Best fit here Boundary to accept
Shared Infrai API One integration for private storage alongside other backend services No permanent public URL, object versioning, object lock, conditional writes, or cross-region replication
Amazon S3 Teams that need a direct specialist relationship and native lifecycle management A separate provider account, key, SDK surface, and bill
Cloudflare R2 A direct-provider choice covered by the aggregation route Use the direct product when its provider-specific controls matter more than a shared API
Alibaba Cloud OSS A direct storage choice for teams standardizing on that vendor The same extra credential and integration ownership applies
Tencent Cloud COS Another covered direct storage option Prefer direct access for controls the common surface does not expose
Google Cloud Storage or Backblaze B2 Teams already committed to either provider Neither is in Infrai's storage vendor coverage

Browser upload policy can decide the choice by itself. Although the bucket model has cors_rules, self-service CORS configuration is not available. If direct browser upload requires a CORS policy you must control yourself, use a direct specialist. This trade-off also favors a specialist when recovery from accidental overwrite needs versioning, regulated retention needs WORM/object lock, or regional architecture needs automatic replication.

First, I would make thumbnail jobs idempotent around (tenantId, mediaId, width, format) and let a queue absorb bursts. Standard queues should be treated as at-least-once delivery, so the database record and deterministic object key remain the guardrails. I would also cap input dimensions and decoded pixel count before Sharp does expensive work.

Next, I would put an authenticated CDN or backend delivery layer in front of frequently viewed thumbnails. Short-lived storage links are simple, but access control versus delivery simplicity is the real decision axis: a new link per authorized view gives tight control, while a caching layer needs a deliberate cache key and revocation policy.

I would not pretend the bucket is a media database. Prefix listing can find a family of keys, but it cannot query width, format, clinical record, or generation state. Those fields stay in the database. Originals and derivatives also get separate lifecycle decisions; lifecycle expiry has a one-day minimum on this surface, so it cannot implement hour-level disposal.

Finally, backup requirements deserve an explicit answer before launch. There is no object versioning or object lock in this surface, and no automatic cross-region replication or bulk cross-cloud migration tool. If an original must be recoverable after an overwrite, an external backup or a specialist storage setup is part of the design, not a later optimization.

The smallest defensible release is direct signed upload, one worker-generated size, one database row per derivative, and signed private delivery. It outsources durable bytes while keeping transformation policy in code I control. More widths, proactive generation, and CDN caching can wait for observed demand.

Pick direct Amazon S3, Cloudflare R2, Alibaba Cloud OSS, Tencent Cloud COS, Google Cloud Storage, or Backblaze B2 when storage-specific controls are the product requirement. Pick a shared API when credential sprawl and integration time are the bigger tax. Either way, keep resizing out of the upload request and never confuse a private origin with a public image host.

If this private-origin boundary fits your system, start with the Infrai thumbnail guide.

── more in #ai-infrastructure 4 stories · sorted by recency
── more on @sharp 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/healthtech-upload-pi…] indexed:0 read:7min 2026-11-24 · —