Node.js AI Image Generation Save Pipeline for Tenant-Isolated Compatible Object Storage A developer outlined a Node.js pipeline for storing AI-generated property-report images in tenant-isolated S3-compatible object storage, recommending that servers receive binary responses when possible and otherwise perform a single strict Base64 decode into a Buffer. The approach strips only a declared data-URL prefix, validates the Base64 alphabet and padding, verifies the PNG signature before upload, and derives the tenant ID and object key from trusted server-side identifiers rather than payload fields. TL;DR: For generated property-report images, keep bytes as bytes whenever possible. If an upstream API returns Base64, strip only a declared data-URL prefix, validate the alphabet and padding, decode once into a Node.js Buffer , verify the PNG signature, and upload that buffer with an explicit media type. Put the tenant ID in trusted server-side metadata and in the object key; never derive it from the Base64 payload or a browser-supplied path. | Choice | Decode boundary | Tenant-isolation risk | Operational burden | |---|---|---|---| | Binary response to server | None | Lowest: server chooses the key | Low | | Base64 response to server | One strict decode | Low if validation happens before upload | Medium | | Browser uploads generated bytes | Browser plus storage boundary | Higher: authorization paths multiply | High | Recommendation: Use the first option when the image generator can return binary. Otherwise use the second. A browser-to-object-store path is the runner-up, useful for large customer-originated files, but it adds little value when a server already receives generated report artwork. For a one-person SaaS, fewer authorization surfaces protect shipping time. Base64 is a transport encoding, not an image format. Four different values often get called “the image”: a data URL, a raw Base64 string, decoded bytes, and a PNG file. Passing the first value to a decoder that expects the second is enough to produce bad output. So are truncated padding, whitespace introduced by wrapping, or decoding a value twice. Node.js adds a subtle trap. Its Buffer.from value, "base64" decoder accepts the URL-safe alphabet and ignores whitespace in Base64 input. That tolerance helps interoperability, but it means decoding without throwing is not proof that the producer sent the exact representation your application contract requires. Validate first. The object-storage upload is usually downstream of the real fault. An S3-compatible service stores the bytes it receives; a .png key and an image/png content type do not transform text into an image. Treat a malformed-image report as a boundary problem before treating it as a storage problem. Consider the whole failure chain. A generator returns a data URL, application code passes that complete string to a permissive decoder, the resulting bytes are uploaded under a plausible PNG key, and the database marks the report asset ready because the write completed. The customer then opens the report and sees a broken image. Storage metrics stay green throughout. Checking the representation and PNG signature before the write moves that failure to the one place where it can still be classified accurately, retried safely, and kept out of the customer-visible record. For property management, that boundary is also a security boundary. A generated inspection chart for tenant t 4821 must never land under another tenant's prefix, even when a retry reuses a report ID. The authenticated server should resolve tenant ownership from its own session and database record. Payload fields are not authority. The first criterion is where text becomes bytes . One conversion point is easy to test. More than one invites double decoding and accidental UTF-8 conversion. Keep a small contract around the generator result: either { kind: "bytes", data: Buffer } or { kind: "base64", data: string } . Do not accept a union of data URLs, arbitrary strings, arrays, and buffers at the upload call. The second is who chooses the storage identity . Build the object key after authorization from immutable server-side identifiers. A shape such as tenants/