Open QurQuma opened 3 years ago
Actually Buddypress docs lose his link from the uploaded media.
Could you say more about this? Exactly what is happening?
Hi,
Thanks very much. One more question: What should the URL look like?
You're so welcome!
It has to take URL from this:
this is the link to amazon file over the bucket.
Actually it looks like this: https://AMAZON_S3_BUCKET_NAME.s3.eu-west-3.amazonaws.com/website/wp-content/uploads/2020/10/13174853/120809262_1696870730475433_6852389121015225895_o.jpg
Is this the information you need?
Thanks
Yes, that's what I need - I need to understand how the Offload plugin filters URLs.
Can you confirm that this is the plugin you're using? https://wordpress.org/plugins/amazon-s3-and-cloudfront/
If so, I'll take a look to see if there's a simple way to apply the plugin's filters to the Docs attachment links.
Yes, exactly. Thanks!
Updates about this? Thanks @boonebgorges
I had a look and it looks like this is a minimal solution. In a plugin or a theme file:
add_filter(
'bp_docs_attachment_url_base',
function( $att_url, $attachment ) {
$att_url = wp_get_attachment_url( $attachment->ID );
return apply_filters( 'as3cf_filter_post_local_to_provider', $att_url );
},
10,
2
);
Note that this doesn't do any attachment protection, so that the docs are downloadable by anyone who has the URL.
If this works for you, I can examine how/whether to build support for this feature into buddypress-docs itself.
It work perfectly for me, @boonebgorges. I'm here to support for every further step to improve protection (how does it work with actual implementation?).
The Doc protection feature has two parts.
Direct download URLs are masked. For a doc with URL like example.com/docs/test-doc, attachment download links appear as example.com/docs/test-doc?bp-attachment=image.jpg. WP then catches these ?bp-attachment
requests and serves the file using readfile()
. This prevents people from seeing the actual URL filepath (in wp-content).
Second, direct access to files is blocked, when using Apache. An .htaccess file is automatically placed in the wp-content directory that contains the attachments for a non-public Doc, and that .htaccess file redirects requests for files inside of that directory to the corresponding ?bp-attachment
URL.
It's not clear to me how 2 would be possible with files offloaded to S3.
We might be able to accomplish some version of 1, but it would require PHP-level redirects to the S3 URL.
Ok, it would be great to implement 1. As for 2. isn't yet possible to allow access to amazon s3 buckets only from a specific website? It would be possible to solve this way, but I'm not sure about this.
I’d like to use docs joined with Amazon S3 Offload, a plugin that automatically move all of the uploaded media to an S3 bucket. Actually Buddypress docs lose his link from the uploaded media. Is there a way to fix this? This would be very useful to not overload wp platform resources. Thanks, Francesco