Your editorial team uploaded 180GB of product photography to /wp-content/uploads over four years. The hosting plan’s disk is full, the backups take six hours, and the next migration estimate quotes the transfer alone at a full weekend. The obvious answer is to push uploads to S3 (or R2, or MinIO) and serve them from a CDN — and then you discover the plugin registry has two viable candidates, three rewrite strategies, and a “import existing media” job that locks the WP-CLI session for hours and silently skips files. The work is not in the plugin install. The work is in the migration plan.
What’s happening
WordPress treats /wp-content/uploads as a local path. When you upload an image through the media library, wp_handle_upload() writes it to that path, then wp_generate_attachment_metadata() creates the thumbnail sizes (thumbnail, medium, medium_large, large, plus any theme/plugin-registered sizes) in the same directory. The attachment post stores the path in _wp_attached_file postmeta and the size variants in _wp_attachment_metadata. The frontend builds URLs by prepending the site’s upload_url_path.
Offloading replaces the storage layer but has to preserve those metadata records — otherwise wp_get_attachment_image_src() returns broken paths. There are two production-grade plugins:
- WP Offload Media (Delicious Brains / WP Engine). Hooks
wp_handle_upload_prefilterandwp_generate_attachment_metadata, uploads to S3 immediately after thumbnail generation, rewrites attachment URLs throughwp_get_attachment_urlfilter. Stores the bucket key inamazonS3_infopostmeta. Optional “remove from local server” deletes the local file after upload. - Media Cloud (Interfacelab). Broader scope — imaging pipeline, dynamic resize, multiple storage backends. Hooks the same filters but keeps its own metadata in
ilab_s3_infopostmeta. Heavier; opinionated about image processing.
The rewrite strategy is the second decision. Three options:
- Direct S3 URLs (
https://my-bucket.s3.amazonaws.com/wp-content/uploads/2026/05/photo.jpg). Simplest. Exposes the bucket name in every URL. CORS becomes load-bearing. - Custom domain on the bucket (
media.example.com→ S3 via DNS CNAME or CDN). Cleaner URLs, but the cert and the CDN config become part of the WordPress deploy. - CDN-fronted with a different path (
cdn.example.com/uploads/...). Strips the WP path structure, requires the plugin to know how to rewrite both the upload key and the public URL.
The migration itself is where most rollouts stall. WP Offload Media’s “Tools → Upload to bucket” runs wp-cli media regenerate-style work serially. On a library with 200,000 attachments it takes hours, holds a database lock, and on the slightest network blip leaves attachments half-migrated — present on S3 but amazonS3_info postmeta not written.
The fallback question — what happens when S3 is down or the plugin is deactivated — is rarely answered up front. Without a fallback, deactivating the offload plugin means every image on the site 404s.
How to verify
Before migration, audit what you’re moving:
# Total uploads size
du -sh /home/acmewp/public_html/wp-content/uploads/
# Count of attachments in DB vs files on disk
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type='attachment'" --skip-column-names
find /home/acmewp/public_html/wp-content/uploads -type f \
\( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.webp' -o -iname '*.gif' -o -iname '*.svg' \) \
| wc -l
# Top 20 largest files — usually identifies the cleanup wins before you migrate
find /home/acmewp/public_html/wp-content/uploads -type f -printf '%s %p\n' \
| sort -rn | head -20 | numfmt --to=iec --field=1
If the file count significantly exceeds the attachment count, you have orphans — files on disk that no _wp_attached_file postmeta references. Migrating those is wasted egress. After installing WP Offload Media but before migrating:
# Confirm the plugin sees the bucket
wp option get tantan_wordpress_s3 --format=json
# Check that a test upload reaches the bucket
wp media import /tmp/test-photo.jpg --post_id=1
aws s3 ls s3://my-bucket/wp-content/uploads/$(date +%Y/%m)/ --endpoint-url=https://s3.example.com
After migration, the audit query that catches half-migrated state:
-- Attachments that exist as post but have no S3 metadata
SELECT p.ID, p.post_title
FROM wp_posts p
LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = 'amazonS3_info'
WHERE p.post_type = 'attachment' AND pm.meta_id IS NULL;
Any non-empty result is an attachment the plugin thinks is local. Either re-run the migration for those IDs, or accept that they’ll keep serving from /wp-content/uploads/ (and never delete the local files).
The fix
A migration plan that survives 200k+ attachments:
Phase 1 — Pre-migration cleanup. Before moving anything, clean the library. Delete obvious orphans, run a duplicate-finder plugin offline, regenerate any size that’s no longer used. Every file you don’t migrate is bandwidth saved.
Phase 2 — Parallel sync, not plugin-driven import. WP Offload Media’s UI-driven import is fine for libraries under 5GB. Above that, do the bulk transfer with aws s3 sync (or rclone sync for non-AWS backends) and let the plugin only handle the metadata backfill:
# Bulk transfer with parallelism
aws s3 sync /home/acmewp/public_html/wp-content/uploads/ \
s3://my-bucket/wp-content/uploads/ \
--endpoint-url=https://s3.example.com \
--storage-class STANDARD \
--exclude "*.db" --exclude "*-cache/*" \
--cli-write-timeout 0 --cli-read-timeout 0
# For S3-compatible (R2, MinIO, Garage), prefer rclone — better resumability
rclone sync /home/acmewp/public_html/wp-content/uploads/ remote:my-bucket/wp-content/uploads/ \
--transfers 16 --checkers 32 --progress \
--s3-upload-concurrency 8
Run from a host with adequate egress bandwidth. On a busy production server, throttle (--bwlimit 50M on rclone) so you don’t starve the live site.
Phase 3 — Metadata backfill via WP-CLI. Once files are on the bucket, tell WP Offload Media to register the existing keys instead of re-uploading:
wp s3-uploads upload-attachment <attachment-id> # if using human-made/s3-uploads plugin
# OR for WP Offload Media:
wp as3cf upload-bucket <attachment-id> --batch=200
Batch in chunks of 200-500. The --batch flag commits between batches so a crash doesn’t roll back the whole job.
Phase 4 — Rewrite strategy and fallback. Configure URL rewriting in wp-config.php so the plugin’s behavior is deterministic:
// wp-config.php — pin the offload behavior so a plugin update can't surprise you
define('AS3CF_SETTINGS', serialize([
'provider' => 's3',
'access-key-id' => getenv('S3_ACCESS_KEY'),
'secret-access-key' => getenv('S3_SECRET_KEY'),
'bucket' => 'my-bucket',
'region' => 'auto',
'use-server-roles' => false,
'enable-object-prefix' => true,
'object-prefix' => 'wp-content/uploads/',
'copy-to-s3' => true,
'serve-from-s3' => true,
'remove-local-file' => false, // keep local until migration is fully verified
'force-https' => true,
'object-versioning' => false,
'use-yearmonth-folders' => true,
'domain' => 'cloudfront',
'cloudfront' => 'media.example.com',
]));
The remove-local-file => false setting is critical for the first 30 days. Keep the local files until you’ve verified every URL on every page resolves through the CDN. After 30 days of monitoring, run a cleanup pass that deletes only files confirmed present in the bucket:
# For each local file, verify it's in the bucket before deleting
find /home/acmewp/public_html/wp-content/uploads -type f | while read f; do
key="wp-content/uploads/${f#*/wp-content/uploads/}"
if aws s3api head-object --bucket my-bucket --key "$key" \
--endpoint-url=https://s3.example.com >/dev/null 2>&1; then
rm "$f"
fi
done
Phase 5 — Define the fallback. If S3 is unreachable, what happens? Two defensible answers:
- Origin-pull CDN with stale-while-revalidate. CDN keeps a long cache and serves stale on origin failure. Image URLs stay alive even if the bucket is unreachable; new uploads queue at the plugin level.
- Dual-write to local + S3 for a grace period. Set
remove-local-file => falsepermanently for new uploads in regulated environments. Doubles storage cost; pays for itself the first time a credential expires.
Configure the CDN cache headers explicitly:
aws s3 cp s3://my-bucket/wp-content/uploads/ s3://my-bucket/wp-content/uploads/ \
--recursive --metadata-directive REPLACE \
--cache-control "public, max-age=31536000, immutable" \
--endpoint-url=https://s3.example.com
For private/non-public uploads (membership sites, learning platforms), use signed URLs — but expect to spend a week on plugin compatibility, since many WordPress plugins assume public attachment URLs.
Stack Harbor plans and executes media library offloads (and migrations to S3-compatible storage in general) as part of our enterprise WordPress hosting operating model. If your uploads directory has outgrown the hosting plan and you’d like a migration that doesn’t lock the site for a weekend, start the conversation.