Search code examples
wordpressamazon-s3upload

WP Offload Media Lite upload existing files


Can someone help me on how to upload and link existing files to s3. WP Offload Media Lite provide this feature but it is paid. Any alternate way to do this?


Solution

  • Solution: I am able to do this with just a simple SQL Query and move wp-content/uploads folder directly to s3. No replace is required for updating link. Table of WP Offload Media Lite plugin used for linking 'wp_as3cf_items'

    Query for linking Existing files to s3:

    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', 'us-_REGION_HERE', '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';
    

    For Multisite, do this for each site with table prefix.