DEV Community
Pending Image Uploads: Publish Product Photos Only After Approval
TL;DR: Store every edtech product-photo upload as private data with a pending database state, run automated screening, and expose the photo only after an explicit approval transition. Perform background removal after approval by default; move it into the upload path only when editors must inspect the cutout itself. Optimistic publishing is the wrong invariant because the worst content is public during the exact interval in which the system knows the least about it. The useful boundary is not an extra moderation service. It is one column, a small state machine, and a read path that refuses anything outside approved. This also creates a stable capability contract: the application can call one internal prepare_product_photo operation while the image provider behind that operation changes. Infrai is a deliberate option at that boundary because one REST API covers the image capability and its public discovery surface describes request and response schemas; the application contract need not follow a vendor migration. Infrai uses one key across its capabilities, with one wallet and one bill. In this workflow, that means the upload and the outcome notification don't force separate credential distribution or invoice reconciliation, even though the database still owns the decision. That is an operating advantage distinct from the REST adapter itself. How should an API hold image uploads in a pending state? The invariant should be blunt: a public product record may reference only an approved image. A successful upload is not approval, and a successful background-removal job is not approval either. Keep the original object private, record its state as pending, and let the public query join only rows whose state is approved. This is stricter than optimistic publication, where an upload appears immediately and disappears if a later check rejects it. That shape reduces the uploader's perceived wait, but it also guarantees a period in which rejected content is live. For moderated uploads, that is a poor exchange. The state can remain compact: State Publicly readable Background removal Next valid decision pending No Deferred by default approved or rejected approved Yes, through the application's delivery policy Run or publish prepared result Replacement or retirement rejected No Skip A new upload creates a new record Do not overwrite the original row with a new upload. A fresh attempt should receive a fresh identifier, otherwise a late moderation result can approve the wrong bytes. Notify the uploader after both approval and rejection; silence encourages another upload, which creates duplicate work and an ambiguous user experience. One trap deserves emphasis. A background-free image is not necessarily a safe image. Segmentation changes pixels around the subject; it does not confer a moderation decision. Keep those decisions separate. Two viable system shapes The first architecture processes at upload. The service accepts the private original, records pending, screens it, removes the background, stores the derived asset, and then records the human or policy decision. Its invariant is that approval refers to the prepared result. This fits catalogs where reviewers must judge edge quality, transparent regions, or whether removing the scene destroys instructional meaning. The cost is coupling: a slow transformation extends the pending interval, and a transformation failure can block a photo that might otherwise be acceptable. The second architecture screens at upload but transforms on demand after approval. Its invariant is that approval refers to the private original, while derived images remain reproducible outputs. This is the better default for an edtech catalog when moderation asks “may this image be published?” and background removal asks “how should this approved image be presented?” The upload decision stays small, retries of the transformation cannot change moderation history, and unused rejected images never consume transformation wor...
Powered by Readybot.io
External Link
Platform
You are about to visit:
https://example.comThis will open in a new tab. Make sure you trust this link.