Operate · 06
Media library
The media library is the shared asset source for the storefront, Content Studio, journal, banners and Email Studio. One record should serve every surface that needs the same image.

The library
/dashboard/media/ provides a searchable grid, folders, asset detail, alt text, tags, dimensions and usage information. Uploads are available from the library and from the Content Studio, email and banner inspectors through the media picker.
Supported asset roles include portrait, landscape, gallery, poster, video and document. Use the role that matches the surface; the product page and collection cards expect specific crops.
Folders and metadata
Create a folder for a campaign, product line or editorial story before uploading. Renaming a folder keeps its assets; deleting a folder moves its assets rather than deleting them. The quick menu exposes edit, copy URL, download, favourite and delete actions.
| Field | Use |
|---|---|
| Name | Human-readable label used in search and the picker. |
| Alt text | Accessible description; required for meaningful storefront images. |
| Tags | Comma-separated search terms. |
| Folder | Grouping for campaigns and product families. |
| Role | Portrait, landscape, gallery, poster, video or document. |
Upload limits
Django accepts files up to 25 MB in memory and Nginx allows a 30 MB request body. Product photography should be compressed before upload; the browser does not resize originals. The media API returns up to 80 matching images for the picker.
# Check the effective limits
.venv/bin/python - <<'PY'
from django.conf import settings
print(settings.DATA_UPLOAD_MAX_MEMORY_SIZE)
print(settings.FILE_UPLOAD_MAX_MEMORY_SIZE)
PY
Storage and serving
Two storage modes are supported. Local disk is the default: Nginx serves /media/ from /srv/perfumz/media/, while Django serves it in development. S3 + CloudFront is enabled with USE_S3=1: media goes to the media/ prefix, collected static to static/, and CloudFront delivers both.
| Asset | Local mode | S3 / CloudFront mode |
|---|---|---|
| Public media | /media/<key> via Nginx | https://CLOUDFRONT_DOMAIN/media/<key> |
| Static | /static/<key> via Nginx | https://CLOUDFRONT_DOMAIN/static/<key> |
| Private media | /media/private/<key> via authenticated Django view | Local authenticated URL (not uploaded to S3) |
USE_S3=1
AWS_STORAGE_BUCKET_NAME=perfumz-media
AWS_S3_REGION_NAME=me-central-1
CLOUDFRONT_DOMAIN=cdn.perfumz.com
CLOUDFRONT_DISTRIBUTION_ID=E123EXAMPLE
CLOUDFRONT_SIGNED_URLS=1
CLOUDFRONT_KEY_ID=K123EXAMPLE
CLOUDFRONT_PRIVATE_KEY_PATH=/etc/perfumz/cloudfront-private.pemThe local fallback remains production-ready when Nginx serves MEDIA_ROOT. S3 is optional for public assets, but backups always require the private S3 backup bucket.
Deduplication and private media
The upload flow computes a SHA-256 checksum and skips a duplicate file in the same visibility class. Private uploads are stored through the private storage adapter; public uploads through the media adapter. A private asset can be moved to public (or back) from the media drawer or Django admin, and the old public key is queued for CDN invalidation.
Private local files are never exposed by the public Nginx /media/ alias. Nginx proxies /media/private/ to Django, which checks staff or uploader access and returns Cache-Control: private, no-store.
CDN management
The media dashboard shows the active backend, CloudFront host, signed-URL state and pending invalidations. Staff can purge one public asset from the drawer or the whole media library from the header. Invalidation requests are durable database records, processed by the jobs timer or immediately from the CDN admin.
python manage.py invalidate_cdn --path /media/2026/11/bottle.jpg
python manage.py process_cdn_invalidations
python manage.py run_scheduled_jobs --only process_cdn_invalidations
Media backups
create_backup writes media-<timestamp>.tar.gz for local media. S3 media is not copied into that archive; enable bucket versioning plus a replication/backup job for object storage. Restore local media only while the application is stopped or in maintenance mode, then verify a sample image and a product page.
gunzip -c backups/db-<timestamp>.sql.gz | sudo -u postgres psql perfumz
tar -xzf backups/media-<timestamp>.tar.gz -C /srv/perfumz
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Upload returns 413 | Nginx body limit or Django upload limit exceeded. | Reduce the file or raise client_max_body_size and the Django limits together. |
| Image 404 after upload | Media alias, S3 key or permissions are wrong. | Check the Nginx alias or the bucket object key and CloudFront origin path. |
| Image URL uses the S3 hostname | CloudFront is not configured or USE_S3 changed without a restart. | Set CLOUDFRONT_DOMAIN and restart the service. |
| Private asset cannot be opened | You are anonymous or not the uploader/staff. | Sign in as staff or the uploader; private media stays local and requires that authenticated route. |
| CDN purge says not configured | Distribution ID or AWS credentials are missing. | Set CLOUDFRONT_DISTRIBUTION_ID and credentials/IAM role, then restart. |
| Deleted asset still renders | The page or email still references its URL. | Purge the CDN path and update the referencing section or email. |