Prompt
How do I store and serve images in a mobile app backend?
Latest observation
Nov 4, 2026
OpenAI APIWeb search: off
A common, scalable way to handle images in a mobile app backend is:
-
Store the image file in object storage
- Examples: Amazon S3, Google Cloud Storage, Azure Blob Storage, Cloudflare R2
- Don’t store raw image binaries directly in your database unless it’s a very small/simple app.
- The database should usually store metadata only:
- image ID
- user/content ID
- file URL or storage key
- size, MIME type, dimensions
- upload time, status, etc.
-
Upload images from the app to your backend
- Common patterns:
- App → backend → storage: backend receives the file and uploads it to storage.
- App → storage via signed URL: backend gives the app a temporary upload URL, and the app uploads directly to storage.
- The signed URL approach is often better for performance and scalability.
- Common patterns:
-
Serve images via a CDN
- Put a CDN in front of your storage bucket to make images load faster globally.
- Examples: CloudFront, Cloud CDN, Azure CDN, Cloudflare
- The app typically loads images from the CDN URL, not directly from your backend API.
-
Generate different sizes
- Mobile apps usually need thumbnails, medium, and full-size versions.
- You can:
- generate resized versions during upload
- or generate on demand with image-processing services
- This improves loading speed and reduces bandwidth.
-
Control access
- If images are public, serve them with normal CDN URLs.
- If images are private:
- use signed URLs
- or authenticated proxy endpoints
- Avoid exposing storage credentials to the mobile app.
Typical architecture
- Mobile app asks backend to upload an image
- Backend returns a pre-signed upload URL
- App uploads image directly to storage
- Storage event triggers image processing/resizing
- Backend saves metadata in DB
- App requests image list from backend
- Backend returns CDN URLs or signed access URLs
- App displays images from the CDN
Recommended database fields
Example table:
idowner_idstorage_keycdn_urlwidthheightmime_typesize_bytescreated_at
Best practices
- Validate file type and size on upload
- Compress images when possible
- Strip metadata if privacy matters
- Use unique filenames/keys
- Never trust client-provided MIME types alone
- Add rate limiting to uploads
- Use authentication and authorization for private images
- Cache aggressively for public images
Simple rule of thumb
- Binary image data → object storage
- Image metadata → database
- Fast delivery → CDN
- Private access → signed URLs
If you want, I can also show:
- a sample API design
- an AWS S3 implementation
- or a Node.js/Express example for uploads and serving images.