Possibilities of having S3 credentials under A post type for every User?
Hi,
I am trying to break down user to use credentials based on the post(each post will have each own secret key), and when user tries to upload it will reinit the instance with new credentials,
Does that means a rewrite or I can hook the _init and check based on postid?
thanks
@Boby you could conditionally set the S3_UPLOADS constants to user-specific values perhaps. This would look something like:
add_action( 'plugins_loaded', function () {
if ( $_SERVER['REQUEST_URI'] === '/wp-admin/async-upload.php' && isset( $_POST['post_id'] ) ) {
$access_key = get_post_meta( intval( $_POST['post_id'] ), 'aws_acces_key', true );
define( 'S3_UPLOAD_ACCESS_KEY', $access_key );
}
}, 9 ); // hook in before S3 Uploads is loaded
Or something along those lines. Doing it dynamically for S3-Uploads call (like if you needed to upload multiple images from different users in the same request), then that would be a little more tricky.
okay what I understand if we defined the key again to we need to ->get instance again? and setup? @joehoyle
@joehoyle What if I wanted to support multiple S3 endpoints, each with its own credentials, to store multiple files (say, files from 2021 are stored in one bucket, 2022 in a new one), and then the code needs to access some files from 2021 and 2022? As you said, dynamic would be a little more tricky, but what is the direction you'd recommend going in?
Perhaps there could be official support added for multi-endpoint feature? I imagine it could be a relatively common feature request.
Thanks.
We do not intend to add support for this, as we do not use or need this functionality. See our support policy: https://engineering.hmn.md/projects/support/
You're welcome to fork S3 Uploads and add the functionality to your own plugin though :)
@rmccue https://github.com/humanmade/S3-Uploads/pull/603 implements support for this. Please merge and reopen this ticket, then close as fixed?