Logistics Image Reports: Node.js Thumbnail Resize Uploads to Object Storage (Signed Reads)
Short answer: keep original images and generated thumbnails under immutable application keys, issue presigned downloads only after an authorization check, and let a retention job delete both records and objects in a deliberate order. Sharp belongs in the worker that creates derivatives; it should not decide how long a customer's report remains available.
For a logistics product, an image is usually evidence attached to a delivery report: a damaged carton, a pallet seal, or a proof-of-delivery photo. The thumbnail is a convenience, not a second source of truth. That distinction makes the storage design much easier to reason about.
Set deletion rules before writing bytes
Start with a row such as report_images containing a tenant ID, report ID, original object key, thumbnail key, media type, and delete_after timestamp. The keys should be generated by the service, for example tenant/7f/report/91/image/2/original and .../thumb-640, never copied from a customer filename. A database row is the authority for ownership; a private bucket is the byte store.
I once treated deletion as a single DELETE call and then discovered the awkward gap: the database transaction committed, the object request timed out, and the report looked clean while its bytes remained. The fix was a small state machine. Mark the image retiring, enqueue an object deletion, verify the result, and only then mark the row deleted; a retry of the queue item must be idempotent. Keep an audit event with the actor and policy that caused the retirement.
Retention is policy, not a guessed number in a cron script. Legal hold, customer contract, and operational needs can disagree. Store the effective deadline per object, make extensions explicit, and let a lifecycle rule provide a backstop for abandoned prefixes. AWS documents lifecycle management as a set of rules over object age or tags, which is useful for cleanup but does not replace your application record.
How can Node.js upload a resized image thumbnail to compatible object storage?
A request path should authenticate the customer and create a pending image row. A worker reads the original, uses Sharp to produce a bounded thumbnail, uploads both objects through the S3-compatible interface, and changes the row to ready. The download endpoint checks that row against the caller's tenant before it signs a short-lived GET URL. No bucket listing or public ACL is needed.
Ship the row first.
Here is the core worker shape. The endpoint is intentionally provider-neutral; configure the S3 client with the region and endpoint for your chosen compatible service.
import sharp from "sharp"; import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3"; const s3 = new S3Client({ region: process.env.STORAGE_REGION, endpoint: process.env.STORAGE_ENDPOINT, forcePathStyle: process.env.STORAGE_PATH_STYLE === "true", credentials: { accessKeyId: process.env.STORAGE_ACCESS_KEY!, secretAccessKey: process.env.STORAGE_SECRET_KEY!, }, }); export async function createThumbnail( bucket: string, tenantId: string, reportId: string, imageId: string, source: Buffer, ) { const originalKey = `${tenantId}/${reportId}/${imageId}/original`; const thumbnailKey = `${tenantId}/${reportId}/${imageId}/thumb-640.webp`; const thumbnail = await sharp(source) .rotate() .resize({ width: 640, height: 640, fit: "inside", withoutEnlargement: true }) .webp({ quality: 78 }) .toBuffer(); await s3.send(new PutObjectCommand({ Bucket: bucket, Key: thumbnailKey, Body: thumbnail, ContentType: "image/webp", Metadata: { tenant: tenantId, report: reportId, source: originalKey }, })); return { originalKey, thumbnailKey, bytes: thumbnail.byteLength }; } The worker needs a size limit before Sharp sees the buffer, and it should reject formats your threat model does not allow. EXIF orientation is why rotate() appears before resizing. The 640 px width cap keeps a huge camera image from becoming an accidental memory test. I've found that queue latency, transform duration, output bytes, and the count of rows stuck in pending tell you whether to add workers or change the image policy.
Then delete.
Signed reads are temporary capabilities
A presigned URL is a bearer capability. Treat it like a password with an expiry, and never put it in the database as the canonical image address. The route should load the image row, check tenant and report permissions, then sign the exact thumbnail key for a short window. A cache can retain the response, but it must vary by authorization or sit behind a delivery layer that understands private content.
The catch is revocation: an already issued URL can remain usable until it expires. Use a short expiration for sensitive delivery reports, and revoke at the application layer by changing the row state or rotating the key when policy requires immediate denial. Your mileage may vary on the right window; measure the time customers need to open a report instead of copying a universal setting.
Reconcile retention jobs after partial failure
The common failures are ordinary and expensive. A thumbnail is written under a key derived from an untrusted filename, so two tenants collide. A retry creates a second derivative because the job lacks an idempotency key. A delete job removes the row first and loses the key needed to remove the object. A lifecycle rule covers originals but misses the thumb- prefix. A presigned URL is cached for hours while the report was supposed to disappear in minutes.
The storage choice changes the operational work, even when the API looks similar:
| Option | Access shape | Good fit | Main constraint |
|---|---|---|---|
| Managed S3-compatible service | SDK or signed HTTP | Teams that want provider operations | Check lifecycle, region, and egress semantics |
| Self-hosted object store | SDK or signed HTTP | Controlled networks and owned hardware | Your team runs disks, upgrades, and replication |
| CDN in front of private storage | Signed edge request | High thumbnail read volume | Cache invalidation and authorization become coupled |
This is a boundary comparison, not a ranking. Test the exact delete, metadata, and presign behavior against the service you select.
Make the operational checklist part of the implementation: unique keys include tenant and report identity; database transitions are conditional; queue jobs can run twice; deletion scans both original and derivative prefixes; and a daily reconciliation compares ready rows with object metadata. Alert on old retiring rows, not just on worker crashes.
Do not choose this pattern for a public image CDN, collaborative pixel editing, or workloads that require cross-object atomic transactions. In those cases, a delivery service or a database with stronger transactional semantics may be the better fit. Stick with a simpler single-bucket layout when reports are disposable and no tenant-level retention policy exists; the extra state machine earns its keep only when deletion has consequences.
The decision is therefore about lifecycle authority. Let Node.js own identity and authorization, let Sharp own deterministic derivatives, let object storage hold private bytes, and make every retention transition observable. That division stays portable across S3-compatible services without turning the article into a vendor choice.