Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Cloudflare R2 #576

Closed
iasgharalikhan opened this issue May 15, 2022 · 7 comments
Closed

Compatibility with Cloudflare R2 #576

iasgharalikhan opened this issue May 15, 2022 · 7 comments

Comments

@iasgharalikhan
Copy link

Hello,
Since Cloudflare is S3 compatible, can someone share some directions for implementation of S3-Uploads with Cloudflare R2?

@woutersamaey
Copy link

woutersamaey commented Jun 21, 2022

I haven't looked at the code, but I guess all that is needed is to change the API URLs + credentials?
I may investigate this as we will be using CloudFlare for a project soon.

@tedyw
Copy link

tedyw commented Oct 15, 2022

Adding some insight into this. So far this plugin is working well with R2. The only trouble I had was that the default ACL set on upload was not accepted by R2. Looking closer in the R2 docs it is clear that setting ACL on upload is not supported. However setting the value to private will make it work.

Following the plugin docs, this is pretty straight-forward:

define("S3_UPLOADS_OBJECT_ACL", "private");

Also remember to set the custom endpoint pointing to R2 instead of AWS and tell the client use path style endpoint. Do this in the s3_uploads_s3_client_params filter according to the plugin docs. I defined the endpoint in a constant.

function tw_s3_uploads_s3_client_params( $params ) {
    $params["endpoint"] = S3_UPLOADS_ENDPOINT;
    $params["use_path_style_endpoint"] = true;
    return $params;
}

add_filter( "s3_uploads_s3_client_params", "tw_s3_uploads_s3_client_params");

Providing a full example of defined constants. For some context check out an example from CF on how to utilize the aws-sdk for PHP:

define("S3_UPLOADS_ENDPOINT", "https://<Cloudflare account ID>.r2.cloudflarestorage.com")
define("S3_UPLOADS_BUCKET", "<R2 bucket Name>")
define("S3_UPLOADS_BUCKET_URL", "<R2 bucket public url or domain>")
define("S3_UPLOADS_REGION", "auto")
define("S3_UPLOADS_KEY", "<R2 access key ID>")
define("S3_UPLOADS_SECRET", "<R2 secret access key>")

@mathiznogoud
Copy link

Adding some insight into this. So far this plugin is working well with R2. The only trouble I had was that the default ACL set on upload was not accepted by R2. Looking closer in the R2 docs it is clear that setting ACL on upload is not supported. However setting the value to private will make it work.

Following the plugin docs, this is pretty straight-forward:

define("S3_UPLOADS_OBJECT_ACL", "private");

Also remember to set the custom endpoint pointing to R2 instead of AWS and tell the client use path style endpoint. Do this in the s3_uploads_s3_client_params filter according to the plugin docs. I defined the endpoint in a constant.

function tw_s3_uploads_s3_client_params( $params ) {
    $params["endpoint"] = S3_UPLOADS_ENDPOINT;
    $params["use_path_style_endpoint"] = true;
    return $params;
}

add_filter( "s3_uploads_s3_client_params", "tw_s3_uploads_s3_client_params");

Providing a full example of defined constants. For some context check out an example from CF on how to utilize the aws-sdk for PHP:

define("S3_UPLOADS_ENDPOINT", "https://<Cloudflare account ID>.r2.cloudflarestorage.com")
define("S3_UPLOADS_BUCKET", "<R2 bucket Name>")
define("S3_UPLOADS_BUCKET_URL", "<R2 bucket public url or domain>")
define("S3_UPLOADS_REGION", "auto")
define("S3_UPLOADS_KEY", "<R2 access key ID>")
define("S3_UPLOADS_SECRET", "<R2 secret access key>")

dude you're a legend

@rmccue
Copy link
Member

rmccue commented Apr 17, 2023

As we don't use Cloudflare R2, we don't plan to add any specific support for this to S3 Uploads per our support policy. We would accept documentation PRs (e.g. to the "Custom Endpoints" section of the readme) so long as it's clear we're not officially supporting Cloudflare.

I'm glad you were able to get this to work in the meantime!

@rmccue rmccue closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2023
@fernandodilland
Copy link

Adding some insight into this. So far this plugin is working well with R2. The only trouble I had was that the default ACL set on upload was not accepted by R2. Looking closer in the R2 docs it is clear that setting ACL on upload is not supported. However setting the value to private will make it work.

Following the plugin docs, this is pretty straight-forward:

define("S3_UPLOADS_OBJECT_ACL", "private");

Also remember to set the custom endpoint pointing to R2 instead of AWS and tell the client use path style endpoint. Do this in the s3_uploads_s3_client_params filter according to the plugin docs. I defined the endpoint in a constant.

function tw_s3_uploads_s3_client_params( $params ) {
    $params["endpoint"] = S3_UPLOADS_ENDPOINT;
    $params["use_path_style_endpoint"] = true;
    return $params;
}

add_filter( "s3_uploads_s3_client_params", "tw_s3_uploads_s3_client_params");

Providing a full example of defined constants. For some context check out an example from CF on how to utilize the aws-sdk for PHP:

define("S3_UPLOADS_ENDPOINT", "https://<Cloudflare account ID>.r2.cloudflarestorage.com")
define("S3_UPLOADS_BUCKET", "<R2 bucket Name>")
define("S3_UPLOADS_BUCKET_URL", "<R2 bucket public url or domain>")
define("S3_UPLOADS_REGION", "auto")
define("S3_UPLOADS_KEY", "<R2 access key ID>")
define("S3_UPLOADS_SECRET", "<R2 secret access key>")

Thank you very much, it is still working!

@NKNdevs
Copy link

NKNdevs commented May 8, 2024

I'm unclear where this goes.

function tw_s3_uploads_s3_client_params( $params ) {
    $params["endpoint"] = S3_UPLOADS_ENDPOINT;
    $params["use_path_style_endpoint"] = true;
    return $params;
}

add_filter( "s3_uploads_s3_client_params", "tw_s3_uploads_s3_client_params");

I understand the define statments go in wp-config.php, but do the function and filter statements go in here, or in wordpress theme functions.php or somewhere in the plugins/s3-uploads directory.

OK, having read through the documentation with fresh eyes, I now see that I need to create a file:
wp-content/mu-plugins/s3-endpoint.php
and put it in there. I now have a working install. Adding this nugget of wisdom for others in the same position.

@gdarko
Copy link

gdarko commented Jul 9, 2024

@rmccue - What a pity to decide to not support R2 which is couple additions of code and much better compared to AWS S3 in terms of costs and performance. But anyway this is free software and i respect your decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants