Attach Photos to Reviews
A review lists its photos in images, each with the src of a photo on a public server and an optional label. The label is the photo’s alt text, at most 50 characters. Every app can upload photos to the Mangrove file server, whichever key signs its reviews. The schema guide defines the field.
Upload the photos
Upload the photos before the review, at most 5 for a review, as multipart/form-data with PUT to https://upload.mangrove.reviews. The answer lists the base64url SHA-256 hash of each photo in the order of the upload, and https://files.mangrove.reviews/<hash> serves the photo:
const form = new FormData()
for (const photo of photos) form.append('files', photo)
const response = await fetch('https://upload.mangrove.reviews', { method: 'PUT', body: form })
if (!response.ok) throw new Error(`Upload answered ${response.status}`)
const hashes = await response.json()
const images = hashes.map((hash) => ({ src: `https://files.mangrove.reviews/${hash}` }))
Add images to the review payload, and sign and submit the review as the app does for every review. A photo that no review lists within a day is deleted.
Size and format
The upload service keeps JPEG, PNG, GIF and WebP photos. A request must stay under about 4.5 MB in all, and a larger request fails before the service runs. Scale each photo to fit within 1000 by 1000 pixels as a JPEG before the upload, as the Mangrove apps do, so a phone photo of several megabytes fits. A photo’s address is the hash of its bytes, so its file never changes, and browsers and caches keep it for a year.
A failed upload
When the upload fails, keep the review unposted and tell the person, since the review without its photos says less than they wrote. The person can then remove a photo or try again.