Support » Plugin: WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage » Use WP Offload S3 to access non-attachment objects in an S3 bucket

  • ralbatross

    (@ralbatross)


    I have an S3 bucket that contains a number of images that are uploaded using a script, so they are not associated with a particular post and have no attachment id, etc in WordPress. The bucket has a folder structure like this:

    lwcbimages/wp-content/uploads/system5/product_images

    I would like to be able to use WP Offload S3’s API to take urls like this:

    https://<domain>/wp-content/uploads/system5/product_images/ip298187.jpg

    and convert them to:

    https://s3.amazonaws.com/lwcbimages/wp-content/uploads/system5/product_images/ip298187.jpg

    The reason I want to be able to use WP Offload S3 is because it also already has a functioning AWS client that can pull those urls using the AWS credentials I have set up in the plugin settings, (and I’m trying to avoid simply setting the bucket’s policy to have all objects be public).

    Using the as3cf_filter_post_local_to_s3 filter does not work because the urls in question are not associated with a post or attachment entry in the WordPress DB. But the images are located in a folder that should be accessible to the plugin.

    Is there any way to use the WP Offload S3 plugin’s API to achieve my goal here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • ralbatross

    (@ralbatross)

    Something like this inside of a function seems to do the trick:

    global $as3cf;
    
    if ( $as3cf ) { // Make sure WP Offload S3 is there
    
        $url = $as3cf->get_s3client($as3cf->get_setting('region'))
                     ->get_object_url( 
                            $as3cf->get_setting('bucket'), 
                            <object key>, 
                            time()+900 
                        );
    }

    This grabs a pre-signed url for <object key>, independent of any attachment ids in WordPress

    • This reply was modified 1 year ago by  ralbatross.
    • This reply was modified 1 year ago by  ralbatross.
    Plugin Contributor ianmjones

    (@ianmjones)

    No, WP Offload S3 Lite is not built for that kind of use, it’s for offloading Media Library items.

    Reaching inside the plugin and calling functions is a recipe for disaster as those functions are likely to change over time.

    The old Amazon Web Services plugin is probably a closer fit, but its effectively deprecated now as we’re no longer using it and have no plans to develop it any further.

    https://wordpress.org/plugins/amazon-web-services/

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use WP Offload S3 to access non-attachment objects in an S3 bucket’ is closed to new replies.