Media Data Model
Each media file has:- ID: Unique numeric identifier
- UUID: Unique universal identifier
- Filename: Sanitized filename
- Content Type: MIME type (e.g.,
image/jpeg,image/png) - Provider: Storage provider (
filesystemors3) - Thumb: Thumbnail filename (auto-generated for images)
- Meta: JSONB metadata (width, height for images)
- URL: Full public URL to access the file
- Created At: Upload timestamp
Uploading Media
- Admin Interface
- API Upload
Supported File Types
Configure allowed extensions in Settings → Upload:Default Extensions
jpg,jpeg: JPEG images (thumbnail generated)png: PNG images (thumbnail generated)gif: GIF images (thumbnail generated)svg: Vector graphics (no thumbnail, uses original)*: Wildcard to allow all file types
Remove
* from the list to restrict uploads to specific extensions onlyFile Size Limits
Configure maximum file size in Settings → Upload → Max File Size:- Default:
5000KB (5 MB) - Enforced during upload
- Returns error if exceeded
Image Processing
Images are automatically processed during upload:Thumbnail Generation
Thumbnail Creation
Thumbnail is generated:
- Max width: 250px
- Height: Proportional (maintains aspect ratio)
- Format: PNG
- Algorithm: Lanczos resampling
Image Metadata
Image files include metadata:meta JSONB field for quick access without reading the file.
Vector Graphics (SVG)
SVG files are handled specially:- No thumbnail generation
- Thumbnail URL points to original file
- No dimension metadata
- Served as-is
Storage Providers
- Filesystem
- S3
Local Filesystem Storage
Store media files on the server’s local filesystem.Configuration:Settings → Upload → Provider:filesystem- Upload Path: Directory to store files (relative or absolute)
- Upload URI: Public URL path to access files
- Simple setup
- No external dependencies
- Fast local access
- No additional costs
- Not scalable for distributed systems
- Requires disk space on server
- No built-in CDN
- Backups needed
Using Media in Campaigns
In HTML Content
Insert media URLs directly into HTML:In Templates
Embed media in templates:In Rich Text Editor
Use the image insertion tool:- Click image icon in toolbar
- Select from uploaded media
- Or paste URL directly
Attaching to Campaigns
Attach media to campaigns for tracking:campaign_media table for analytics.
Managing Media
Viewing Media
List all uploaded media:Searching Media
Search by filename:- Use the search box in admin interface
- Or
?query=parameter in API - Searches
filenamefield
Deleting Media
API deletion:
Filename Handling
Sanitization
Filenames are automatically sanitized during upload:- Non-ASCII characters removed
- Spaces converted to underscores
- Special characters stripped
- Extension preserved
Duplicate Handling
If a filename already exists:- Check database for existing filename
- Generate random 6-character suffix
- Append to filename before extension
Serving S3 Media
For S3 storage with relative public URLs:Direct S3 URLs
Ifpublic_url is set to full domain:
Proxied URLs
Ifpublic_url is relative path:
- Request to
/s3/image.jpg - Fetched from S3
- Served through listmonk
- Content-Type auto-detected
Proxying adds latency. Use CDN with full URLs for better performance.
Database Schema
Campaign-Media Relationship
- Links campaigns to attached media
- Preserves filename even if media is deleted
- Used for tracking media usage
Performance Considerations
Thumbnails
Faster Loading
Thumbnails load quickly in admin interface and media picker
Reduced Bandwidth
Smaller file sizes for preview purposes
Better UX
Instant preview without loading full images
Consistent Size
Uniform thumbnail dimensions for clean layouts
CDN Integration
For S3 storage, use CDN for optimal performance:- Set up CloudFront, Cloudflare, or similar
- Point CDN to S3 bucket
- Set
upload.s3.public_urlto CDN domain - Media URLs will use CDN automatically
Security
Extension Filtering
Restrict file types to prevent malicious uploads:Content Type Validation
Content-Type header is validated during upload:- Checked against file extension
- Stored in database
- Used when serving files
File Size Limits
Enforce size limits to prevent abuse:- Configured in
upload.max_file_size(KB) - Default: 5 MB
- Rejected before processing
Troubleshooting
Upload Fails
Broken Image URLs
- Verify media still exists in database
- Check storage provider is accessible
- For S3: Ensure bucket permissions are correct
- For filesystem: Verify
upload_urimatches web server config
Thumbnails Not Generating
- Only applies to: JPG, PNG, GIF
- SVG files use original as thumbnail
- Check image file is valid format
- Review upload logs for resize errors
API Reference
Upload Media
Get All Media
Get Single Media
Delete Media
Best Practices
Optimize Images
Compress images before upload to reduce file sizes and email load times
Use CDN
For S3 storage, integrate a CDN for faster global delivery
Descriptive Names
Use clear, descriptive filenames for easy identification
Regular Cleanup
Periodically remove unused media to save storage space
Backup Media
Ensure media files are included in backup strategy
Restrict Extensions
Limit allowed file types to only what’s needed