Skip to Content

Offload Media Manual Upload

Prerequisites:

  • AWS CLI installed and configured.
  • Git Bash (or PowerShell) for running commands.
  • R2 bucket set up (e.g., with Cloudflare or another compatible provider).
  • Ensure your WP Offload Media Lite is already set up and configured to use your R2 endpoint.

Step 1: Configure AWS CLI for R2

  1. Install AWS CLI (if not already installed): Download the AWS CLI and follow installation instructions for your platform (Windows, Linux, macOS).

  2. Configure AWS CLI for R2:

    Open Git Bash or PowerShell on Windows and configure the AWS CLI with the R2 endpoint.

    Run the following command:

    terminal
    aws configure --profile a99-cloudflare

    Enter the following details when prompted (replace with your own credentials and region):

    • AWS Access Key ID: XXXXXXXXXXXXXX
    • AWS Secret Access Key: XXXXXXXXXXXXXX
    • Default region name: XXXXXXXXXXXXXX
  3. Update AWS CLI Configuration:

    Now, open the ~/.aws/config file using the following command:

    terminal
    notepad ~/.aws/config

    Under the [profile a99-cloudflare] section, add the R2 endpoint like this:

    [profile a99-cloudflare] region = us-west-002 endpoint_url = https://xxxxxx.r2.cloudflarestorage.com

    Note: Replace the endpoint with your R2 endpoint if you’re using another service (e.g., Cloudflare R2).

  4. Verify Profile:

    To verify your configuration, run the following command:

    terminal
    aws configure list --profile a99-cloudflare

    You should see your configured profile details.


Step 2: Sync Files to R2 Bucket

  1. Sync Media Files:

    To sync only the media files (typically stored in wp-content/uploads), run the following aws s3 sync command:

    terminal
    aws s3 sync /path/to/your/wp-content/uploads s3://cdn.agentimagehosting.com/<project_slug> --exclude "*" --include "20*"
    • Replace /path/to/your/wp-content/uploads with the path to your local WordPress uploads folder.
    • Replace <your-bucket-name> with the name of your R2 bucket (e.g., cdn.agentimagehosting.com).
    • The --include "20*" flag ensures that only media files from the year-based folders (e.g., 2021, 2022) are uploaded.
  2. Verify the Files Have Uploaded:

    After syncing, run the following command to check that the files were uploaded correctly:

    terminal
    aws s3 ls s3://cdn.agentimagehosting.com/<project_slug> --recursive

    This will list the files that have been successfully uploaded to the bucket.

  3. Add entries to wp_as3cf_items table

    Within your project directory, make a temporary file and copy snippet below (offload.sql). Do not commit this file

    • Replace <region> with s3 bucket region.
    • Replace <bucket> with s3 bucket name.
    • Replace all <project_slug> with your project slug.

    Import using wp cli:

    terminal
    wp db import offload.sql

    Check wp_as3cf_items table entries to have the correct paths.

    offload.sql
    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', '<region>', '<bucket>', concat('<project_slug>/', pm.meta_value) AS path, concat('<project_slug>/', pm.meta_value) AS original_path, 0, 'media-library', p.id AS source_id, pm.meta_value AS source_path, pm.meta_value AS original_source_path, 'a:2:{s:13:"private_sizes";a:0:{}s:14:"private_prefix";s:0:"";}', 0, 1 FROM `wp_posts` p LEFT JOIN `wp_postmeta` pm ON pm.post_id = p.id AND pm.meta_key = '_wp_attached_file' WHERE p.post_type = 'attachment';
Last updated on