How should the backend verify that a file was uploaded successfully?
Verify uploaded photos using an authorized upload record, storage metadata, actual size checks, content validation, and a safe transition into the gallery.
How should the backend verify that a file was uploaded successfully?
The backend should verify the expected storage object rather than accepting a browser's success claim. A completed transfer and an accepted gallery image are different states. The server needs evidence that the correct object exists and meets the application's requirements.
Start from the server's upload record
Look up the upload using a server-issued identifier and recheck the current user's permission. Obtain the bucket, key, expected size, and wedding association from that record instead of trusting a new client-supplied location.
Request object metadata through the supported storage API. The S3 HeadObject operation, supported by R2, retrieves metadata without downloading the body. Verify existence and actual byte size, handling failures without marking the item ready.
Validate content before making it viewable
A stored Content-Type can reflect what the uploader claimed. It does not prove the file is a safe, decodable image. Apply trusted content checks, image decoding, and processing limits appropriate to the allowed formats. OWASP's upload guidance explains these validation concerns.
Keep unvalidated uploads private or quarantined. If signed upload permission could still overwrite the object, finalize an immutable processed copy or otherwise prevent a later replacement from bypassing validation.
Make finalization repeatable and recoverable
Update the database status only after the required checks pass. Repeating the completion request should return the existing result rather than create another photo record.
Record rejected and abandoned uploads for cleanup. Handle an object disappearing during processing and a database write failing after storage succeeds. Test a forged completion request, incorrect size, invalid image content, and a valid upload retried after a network interruption. These checks connect storage evidence to a reliable, authorized gallery item.
No. The backend must verify the server-recorded object and its requirements. Client claims cannot establish storage ownership, actual size, or the validity of image content.
No. It retrieves metadata and can confirm object existence and size. Validating image content requires additional trusted checks against the actual bytes and processing limits.
The object could be replaced after validation while upload permission remains valid. Design finalization so the accepted photo cannot silently change to unvalidated content.
Related learning resources
Ready to master AI completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master AI
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

