• Resolved jondcruz

    (@jondcruz)


    Hello,

    For the Offload Media Lite plugin connected to an AWS S3 setup, is there a way to get the S3 location metadata?

    The image is uploaded via the Media Library and I am able to see the corresponding files in the S3 bucket, under the key of:

    bucket-name/wp-media/2022/07/1234567/image.png

    where the “1234567” is some sequential value.

    I am trying to hook into the WP deletion of an image, and I need to manipulate other files that are stored in the same S3 bucket location as the origin image.

    Thank you

    Jon

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Delicious Brains

    (@deliciousbrains)

    Hey Jon,

    First a little bit of info that’ll help you in the future. At time of offload, you can tell WP Offload Media to include some extra files that aren’t part of the normal Media Library metadata (sizes) by using the as3cf_attachment_file_paths filter.

    There’s an example in our Tweaks Plugin.

    https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks/blob/beb2e0f1bba71be7b462a60209e5ff630a57437e/amazon-s3-and-cloudfront-tweaks.php#L708

    When you use that filter, any time files are uploaded to the bucket, downloaded from the bucket, or removed from the bucket, the extra files are included in the action if appropriate.

    In fact, if you implement that filter even now, after the items have already been offloaded, you may still be able to get WP Offload Media to remove those extra files from the bucket when a Media Library item is deleted. But that does depend on whether you’ve already added them to the same bucket path as the known Media Library files.

    Now to your actual question. Probably the simplest method to get a Media Library item’s remote URL is with the global function:

    $url = as3cf_get_attachment_url( $post_id );

    You can then just pull apart the URL to get the bits you want with the standard parse_url function.

    -IJ

    Thread Starter jondcruz

    (@jondcruz)

    Thanks, IJ, for the detailed info and that function.

    It’s saved me quite a bit of time coding.

    Have a good one.

    Jon

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get S3 Object Metadata from Post or Attachment ID’ is closed to new replies.