humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.94k stars 389 forks source link

How to trigger an upload manually #642

Closed goonydev closed 1 year ago

goonydev commented 1 year ago

Hi,

I have a plugin that blocks the resizing of the attachment at first. But then I build my own sizes in a plugin. I do not use the wordpress resizing functions. All I am using is:

wp_update_attachment_metadata()

But that function won't trigger the S3 upload to the bucket. Is there any function, hook that I can fire so that S3 Upload plugin will do it's thing? Again, I don't want to use the WP resizing functions.

Sorry if this is not in the scope of the usual support, since this is not a bug in your plugin. But I hope you can help me figure this out so I can keep using your plugin.

Thank you in advance

joehoyle commented 1 year ago

When you build your own sizes, where are you storing them? If you are putting them in wp_upload_dir() then it should be an s3:// url which would means your sizes are already on s3

goonydev commented 1 year ago

Thank you for the reply. I store the sizes in the regular upload folder, like WP does originally. I use a remote service to resize them and use curl to fetch the resized images. I don't think I can simply put a S3 path and hope it will send them there.

joehoyle commented 1 year ago

Ideally you should be pulling the uploads directory path from wp_upload_dir(), which will be the s3:// path if s3 uploads is enabled. This is a php stream wrapper that supports things like "copy()" etc natively in php. So, you can do something like:

copy( $temp_path, wp_upload_dir()['path'] . '/' . $filename );

That will copy the file to s3 as expected.