WP Offload Media Lite: Offloading all existing media using an SQL query

Assuming you’ve already uploaded all of the contents of the uploads/ folder into the Amazon S3 bucket (set to public), you now need to run the following SQL query to add rows to the wp_as3cf_items table:

INSERT IGNORE INTO wp_as3cf_items (provider, region, bucket, path, original_path, is_private, source_type, source_id, source_path, original_source_path, extra_info, originator, is_verified) 
SELECT 
	'aws', 
	'AWS_REGION_HERE', 
	'AWS_BUCKET_NAME_HERE', 
	CONCAT('wp-content/uploads/', SUBSTRING_INDEX(guid, 'wp-content/uploads/', -1) ) AS path, 
	CONCAT('wp-content/uploads/', SUBSTRING_INDEX(guid, 'wp-content/uploads/', -1) ) AS original_path, 
	0, 
	'media-library', 
	id as source_id, 
	SUBSTRING_INDEX(guid, 'wp-content/uploads/', -1) AS source_path, 
	SUBSTRING_INDEX(guid, 'wp-content/uploads/', -1) AS original_source_path, 
	'a:2:{s:13:"private_sizes";a:0:{}s:14:"private_prefix";s:0:"";}', 
	0, 
	1 
FROM `wp_posts` 
WHERE `post_type` = 'attachment';

Make sure to replace AWS_REGION_HERE and AWS_BUCKET_NAME_HERE above; you may also need to adjust the CONCAT for path and original_path if your bucket has a complex folder structure.

Source:

Leave a Reply

Your email address will not be published. Required fields are marked *