WP Offload S3 Lite
How to update older Image URLs? (17 posts)

  1. rohit@gadgetronica.com
    Posted 3 years ago #

    How do we update the image urls for those files that were uploaded before installing the plugin?


  2. gulflee
    Posted 2 years ago #

    yup, same question here.
    moving older image to s3
    thanks in advance

  3. sforsberg
    Posted 2 years ago #

    Hey, I just ran across this concern as well and I found a solution by using a very convenient plugin called Regenerate Thumbnails Basically all you have to do is:

    1. Install and activate the plugin
    2. Locate the tool within the Tools admin menu link
    3. Click on the Regenerate All Thumbnails button
    4. Wait until the process is completed

    Keep in mind the process can take quite some time to complete depending on the amount of images you have in your media library, so make sure you will maintain a steady and strong connection to the Internet during the process and that you do not close the window that is running the regeneration script. Also make sure your settings for Amazon S3 and Cloudfront are correct and are working before starting the regeneration process.

    This will not regenerate custom thumbnails that are not registered as being a valid image size in your theme and plugins, so as long as the developers of your theme and plugins followed the standard thumbnail creation process as briefly outlined here then you will be all set. Don't worry if the images were invalidly created, if the plugin is able to handle output and storage of the image urls appropriately you won't lose them since none of those images would be overwritten.

    Hope this helps.

  4. samb_nz
    Posted 2 years ago #

    Hey @sforsberg,

    That is a good idea, any other ideas on what you would do for media which isn't images, such as pdf's etc ?


  5. balbert
    Posted 2 years ago #

    any solutions for non images especially when using older multi-site?

    redirect options?

  6. balbert
    Posted 2 years ago #

    Not sure if this will help, but this is how I think we are going to deal with this.

    For images already placed in posts and pages, we've used a redirect in our .htaccess file. for our regular non-multi site wp, we've used:
    RewriteRule ^wp-content/uploads/(.*)$ https://thebucketname.s3.amazonaws.com/wp-content/uploads/$1 [L]
    of course your path might be different.

    For our wp-mu site we've created our own ms-files.php to point to our s3 path and then pointed to it via .htaccess ala this:
    RewriteRule ^(.*/)?files/(.*) wp-content/mu-plugins/vital-scripts/ourown-ms-files.php?file=$2 [L]

    in that file basically we've replaced:
    $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET[ 'file' ] );
    $file = "{$bucket}.s3.amazonaws.com/blogs.dir/{$blog_id}/files" . '/' . str_replace( '..', '', $_GET[ 'file' ] ) ;
    we also removed/updated some of the code to work with S3.

    This is the down and dirty that we've done but since the plugin creates a global object of
    $as3cf you could use that to get your bucket and other features set via the plugin to use in various urls.

    So far it seems to be working.

    Not implemented but and idea for older images that haven't been place into posts yet, you could use the wp_get_attachment_url filter to filter the url before it gets inserted. Doing it on the fly would basically eliminate the need to update the db. Just a thought.


  7. Brad Touesnard
    Plugin Author

    Posted 2 years ago #

    I'd probably use http://wordpress.org/plugins/search-and-replace/ to update those URLs.

  8. TraciBunkers
    Posted 2 years ago #

    I used the plugin Velvet Blues Update URLs and it worked great for changing the URLs in my posts and pages. But when I am in my WP admin and look at the media library, all of the images that I transferred myself to my S3 bucket don't show thumbnails. I'll have to try the regenerate thumbnails to see if that does it. I can probably make changes in my database, but . . .

    Samb_nz--the velvet blues plugin should work for other files as well.

  9. TraciBunkers
    Posted 2 years ago #

    A thumbnail regeneration plugin won't work for this because it looks for the image in the original path.

    Info needs to be placed in the database, but I need help with that. Brad, I found this link you gave in another thread to the code that your plugin adds to the database. Can you tell me what the sql command would be to add the meta_key and meta_value in the wp_postmeta table in the database for the old media files?

  10. samb_nz
    Posted 2 years ago #

    @traciBunkers I also ended up using an .htaccess file in the wp-uploads dir that just redirects to the s3 bucket, and manually uploaded all my old media. That way I didn't have to alter anything in wordpress, then this plugin takes care of any new files.

  11. TraciBunkers
    Posted 2 years ago #

    @samb_nz So, you did the redirect for the links instead of changing them? (I already changed my links with the velvet blues plugin). The only problem I'm having is in the admin for my media library, the thumbnails don't show up for the old files that I manually moved to my S3 bucket. They show up on the posts fine, just not in the admin. It's only a problem if I want to use an older image in a post.

  12. samb_nz
    Posted 2 years ago #

    Yeah @TraciBunkers,

    I used the .htaccess, which meant everything worked as normal in the wordpress admin.

  13. TraciBunkers
    Posted 2 years ago #

    And I JUST realized that none of the thumbnails on my blog show up. SO if someone does a search, none of the results have thumbnails--just a blank box where the image should be. Dang.

  14. almai
    Posted 2 years ago #

    I figured it out:

    1. With some basic SQL knowledge you can determine all posts of post type attachment that do not have an entry with the meta_key "amazonS3_info" in the table wp_postmeta.
    2. Extract the file name of each attachment from the old guid in wp_posts.
    3. Add for each attachment a line like the following to functions.php and refresh the website: add_post_meta( 2868, 'amazonS3_info', array('bucket' => "your-bucket", 'key' => "path/to/media/in/bucket"));
  15. almai
    Posted 2 years ago #

    In addition to the previously mentioned solution you should dump the database and replace all old URLs that point to the media files, e.g:
    sed 's/http:\/\/domain.de\/media/http:\/\/cdn.domain.de\/media/g' old.sql > new.sql

  16. Brad Touesnard
    Plugin Author

    Posted 2 years ago #

    I'd be careful doing find & replace on SQL like that. You should use http://wordpress.org/plugins/wp-migrate-db/ instead.

  17. weizhuus
    Posted 2 years ago #

    @TraciBunkers, for the thumbnail, I think the issue is that the new url is not in the post it self. It stores somewhere else. So the replace url in the post won't fix those thumbnail url. I think you need to replace those by a straight sql. I will dig a bit more if I need to resolve the issue myself.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Offload S3 Lite
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic