S3 url has extra "-"



  • I installed MediaCloud (free version so far) in an AWS EC2 instance, running wordpress 5.2.2. I previously used "WP Offload Media Lite" and have some images in S3 others local on the host. When using "WP Offload Media LIte", the url for the image is something like :
    "https://s3.amazonaws.com/wp-images-mm/wp-content/uploads/2019/....",
    and works as expected. If I turn off that plugin, and turn on MediaCloud, the url in "media library" becomes:
    "https://s3-.amazonaws.com/wp-images-mm/wp-content/uploads/2019/...." (notice the dash after s3). How is that being set? This also breaks the website for any images that were already stored in S3.

    If I upload an image with MediaCloud, then it creates a link as expected, although slightly differently:
    "https://wp-images-mm.s3.amazonaws.com/2019/07/..."

    Tx,
    Pete



  • @Pete-Silva

    Hey Pete,

    I've identified the issue and a fix will be coming out in the morning (it's 2am here, so in about 8 hours). It looks like offload is no longer keeping region info in their metadata for the image.

    If you're feeling adventurous you can make the fix your self. In classes/Tools/Storage/StorageTool.php on, or around, line 1221 is a method called getOffloadS3URL. It looks like this:

    private function getOffloadS3URL($post_id, $info) {
        if(!is_array($info) && (count($info) < 1)) {
            return null;
        }
    
        $region = $info[0]['region'];
        $bucket = $info[0]['bucket'];
        $file = $info[0]['key'];
    
        return "https://s3-$region.amazonaws.com/$bucket/$file";
    }
    

    You can replace it with this:

    private function getOffloadS3URL($post_id, $info) {
        if(!is_array($info) && (count($info) < 1)) {
            return null;
        }
    
        $region = (isset($info[0]['region'])) ? $info[0]['region'] : null;
        $bucket = $info[0]['bucket'];
        $file = $info[0]['key'];
    
        if (empty($region)) {
            return "https://s3.amazonaws.com/$bucket/$file";
        } else {
            return "https://s3-$region.amazonaws.com/$bucket/$file";
        }
    }
    

    Otherwise it'll be part of an update I'm pushing out tomorrow.



  • Wow! Just want to say, that is amazing customer service. i see what you mean by it no longer including region. Will wait for the release. Thank you for the quick response.

    Pete



  • @jong
    Ended up adding your change and still seeing the "s3-." I even changed the code to:

          if(!is_array($info) && (count($info) < 1)) {
                        return "https://s3.amazonaws.com11/$bucket/$file";
                        #return null;
                }
    
                $region = (isset($info[0]['region'])) ? $info[0]['region'] : null;
                $bucket = $info[0]['bucket'];
                $file = $info[0]['key'];
    
                if (empty($region)) {
                        return "https://s3.amazonaws.com22/$bucket/$file";
                } else {
                        return "https://s3-$region.amazonaws.com33/$bucket/$file";
                }
        }
    

    And I still get https://s3-.amazonaws.com/wp-images-mm/... I then deleted and reinstalled the plugin.. then I added the above code -- and still get: 212f5609-2cc7-4f29-a02a-8181ac2b1551-image.png

    Pete



  • @Pete-Silva

    Yeah it ended up being a little more complicated. The first time Media Cloud encounters an Offload Media image, it copies that metadata to Media Cloud's metadata format, so it will only generate the URL one time.

    I have the complete fix in but Freemius, the platform we use, is having issues with its deployment tool. So we're having to wait for them before we can distribute the new plugin version. Should be soon.


Log in to reply