Node.js Object Storage: Thumbnail Metadata Not Persisting After Upload
A media training pipeline has two durability problems: thumbnail bytes must survive upload, and descriptive fields must survive the workflow around it. I keep those as separate records. The object carries small headers. A versioned retention manifest carries policy and the link between source and derivatives.
Short answer: compare the exact upload request with a fresh read of the object headers. If the field was absent, fix request construction. If it was present and later absent, a replacement upload or metadata-less copy probably won the race. Verify the object you read, not only the promise returned by the client.
A source frame can produce several resized derivatives, each with a reproducible deletion date. Retention cannot depend on whatever a browser sent with one PUT.
How can thumbnail metadata persist after an object storage upload?
Record the object key, version or generation identifier when storage exposes one, upload metadata, response status, and a subsequent header read. Keep pixels out of the diagnostic record.
There are three useful states:
- The uploader never sent the field. A client option may sit beside, rather than inside, the request metadata option.
- The field was sent, but a later copy or replace created a new object without copying metadata.
- The field is present, but the reader is checking a different key or transformed representation.
A resize worker may read original/clip-1842.jpg, write thumb/clip-1842-320.jpg, and then a catalog query the source while displaying the derivative. Same asset family. Different object.
Why does a successful upload still lose the header?
The useful question is not which storage product is broken. It is which operation produced the object I am reading. A worker can have separate paths for the source PUT, derivative stream, temporary-key copy, and repair replacement. If only the first path sets metadata, the system looks healthy until a later writer wins.
Metadata belongs to an object-creation request. Treat a copy that does not explicitly preserve or replace it as a new write with a new contract. This is the boundary I want visible in code review.
Here is the smallest useful adapter. Its generic interface keeps the article about the contract, not one commercial client.
type Ref = { key: string; version?: string }; type Store = { put(ref: Ref, body: NodeJS.ReadableStream, options: { contentType: string; metadata: Record<string, string>; }): Promise<{ version?: string }>; head(ref: Ref): Promise<{ metadata: Record<string, string> }>; }; async function putThumbnail(store: Store, ref: Ref, body: NodeJS.ReadableStream) { const expected = { "thumbnail-source-key": "original/clip-1842.jpg", "thumbnail-width": "320", "thumbnail-height": "180", }; const result = await store.put(ref, body, { contentType: "image/jpeg", metadata: expected, }); const committed = { ...ref, version: result.version }; const observed = await store.head(committed); for (const [key, value] of Object.entries(expected)) { if (observed.metadata[key] !== value) throw new Error(`missing ${key}`); } return committed; } The read catches a wrong option name, key normalization, and a write aimed at the wrong object. It cannot stop a later writer. For that, own the key and emit an event containing the object version.
How do you make deletion reproducible?
Put retention in a manifest that is immutable by convention and versioned by schema. Store the source reference, every derivative reference, policy input, computed expiration timestamp, and the event that established the policy. The header can support delivery-time checks; it must not be the only copy of the deletion rule.
The deletion worker reads the manifest, validates its schema, deletes the recorded version when versioned storage is available, and records the result. A retry should distinguish “already absent” from “deleted,” but neither outcome should invent a new key. The policy clock needs one owner. If upload, derivative completion, and approval can each start retention, two engineers can calculate different deadlines from one asset.
GDPR Article 20 describes a right to receive personal data in a structured, commonly used, machine-readable format in certain cases. A manifest naming source and derivative objects, media types, and policy history gives an export job more than a directory listing. It does not classify a training frame as personal data; that remains a separate decision.
At small volume, a post-upload HEAD check plus a manifest write exposes most metadata loss. At scale, add a write intent ID to logs and durable events, and include the object version rather than only a logical asset ID. Test repair jobs too: create a derivative, replace it through the production path, assert the manifest points to the final version, then run deletion twice. The second run should be explicitly idempotent.
Do not build a configuration maze. Three metadata fields, one manifest schema, one verification boundary. The limitation is operational: this trade-off adds a second write and a reconciliation path. It is the wrong fit for a tiny one-shot thumbnail service when no retention or export decision depends on the field; one object header may be enough there. Object metadata is a cache of facts needed beside the bytes, while the retention manifest controls lifecycle. When a thumbnail header goes missing, trace the writer that produced the observed version before changing the reader.
Sources
- RFC 9110, HTTP Semantics: https://www.rfc-editor.org/rfc/rfc9110
- GDPR Article 20, Right to data portability: https://gdpr-info.eu/art-20-gdpr/
- RFC 3339, Date and Time on the Internet: https://www.rfc-editor.org/rfc/rfc3339