jrrdnx / craft-cloudflare-r2 Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Can you make it work with https://github.com/kennethormandy/craft-s3securedownloads/?
Thanks.
Hi! First of all thanks for the plugin. I've found two possible bugs that may or may not be related to the plugin or craft itself.
I've noticed when removing media, it doesn't remove all the image transforms from R2. The same thing happens when you replace a file with another file with the same name -- it doesn't replace/remove the transforms. It does seem to do this for the predefined image transforms, but not the ones created from twig/graphql with dynamic dimensions.
When replacing an image with another image with a different name, it will create renamed transforms for the new file but also not remove existing transforms.
Another perhaps related issue is that the "Asset indexes" update will prompt you to delete all the files from R2 -- it doesn't seem to be able to find them in the remote filesystem? I also cannot restore them from the R2 filesystem back into the asset index this way.
The Cloudflare R2 Buckets which are restricted to the EU have an alternative URL. But the URL is hard-coded right now.
See: https://developers.cloudflare.com/r2/reference/data-location/#using-jurisdictions-with-the-s3-api
Would it be possible to support jurisdictions?
It's missing a required param, making the logged exception a generic fallback from Craft. PR-incoming
When trying to copy/duplicate a file or folder, the Flysystem S3 adapter is trying to determine the ACL for the file, which is not supported in R2. As such, trying to move any file results in an error.
2023-08-30 09:02:45 [web.ERROR] [craft\errors\FsException] GuzzleHttp\Exception\ServerException: Server error: `GET https://thejuly-r2-staging.ba3480a1e9cef1fc03b9e0656c55fd28.r2.cloudflarestorage.com//development/freek/dsc_7886_720.jpg?acl` resulted in a `501 Not Implemented` response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>NotImplemented</Code><Message>GetObjectAcl not implemented</Message>< (truncated...)
in /var/www/html/craft/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /var/www/html/craft/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 /var/www/html/craft/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /var/www/html/craft/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(159): GuzzleHttp\Promise\TaskQueue->run()
#5 /var/www/html/craft/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(185): GuzzleHttp\Handler\CurlMultiHandler->tick()
#6 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#7 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#8 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#10 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#11 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#12 /var/www/html/craft/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#13 /var/www/html/craft/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
#14 /var/www/html/craft/vendor/jrrdnx/craft-cloudflare-r2/src/S3Client.php(55): Aws\AwsClient->execute(Object(Aws\Command))
#15 /var/www/html/craft/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php(274): jrrdnx\cloudflarer2\S3Client->execute(Object(Aws\Command))
#16 /var/www/html/craft/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php(419): League\Flysystem\AwsS3V3\AwsS3V3Adapter->visibility('dsc_7886_720.jp...')
#17 /var/www/html/craft/vendor/league/flysystem-aws-s3-v3/AwsS3V3Adapter.php(408): League\Flysystem\AwsS3V3\AwsS3V3Adapter->copy('dsc_7886_720.jp...', 'Testfolder/dsc_...', Object(League\Flysystem\Config))
#18 /var/www/html/craft/vendor/league/flysystem/src/Filesystem.php(122): League\Flysystem\AwsS3V3\AwsS3V3Adapter->move('dsc_7886_720.jp...', 'Testfolder/dsc_...', Object(League\Flysystem\Config))
#19 /var/www/html/craft/vendor/craftcms/flysystem/src/base/FlysystemFs.php(176): League\Flysystem\Filesystem->move('dsc_7886_720.jp...', 'Testfolder/dsc_...')
#20 /var/www/html/craft/vendor/craftcms/cms/src/models/Volume.php(446): craft\flysystem\base\FlysystemFs->renameFile('dsc_7886_720.jp...', 'Testfolder/dsc_...')
#21 /var/www/html/craft/vendor/craftcms/cms/src/elements/Asset.php(3092): craft\models\Volume->renameFile('dsc_7886_720.jp...', 'Testfolder/dsc_...')
#22 /var/www/html/craft/vendor/craftcms/cms/src/elements/Asset.php(2831): craft\elements\Asset->_relocateFile()
#23 /var/www/html/craft/vendor/craftcms/cms/src/services/Elements.php(3170): craft\elements\Asset->afterSave(false)
In R2, objects are currently always treated as private.
Working on a PR to workaround the issue.
Just seen this:
https://blog.cloudflare.com/r2-ga/
I believe it's not beta anymore, and also, public ACL's work!
Hi there,
First and foremost, thank you for this plugin. It works as a charm!
Currently, we have the account id, access key id and secret access key as an environment variable. This works fine for the same account, however when we're trying to develop and want to develop against a development bucket, it doesn't work because the bucket name changes (as expected). Is there a way to also have the bucket name as an environment variable, so we can easily change the environment without persisting/changing settings of a filesystem?
Thanks in advance,
Thijmen
All information available at https://developers.cloudflare.com/images/cloudflare-images/
Also for the custom domain we need to configure the Cloudflare worker
Now I use a simple bash script for uploading images.
#!/bin/bash
folder="./assets"
api_token="qwertyuiopasdfghjklzxcvbnm"
account_id="1234567890qwertyuiop"
# Recursively search through the assets folder
for file in $(find "$folder" -type f ! -name "*.DS_Store"); do
# Get the file's path relative to the assets folder
file_path=${file#"$folder/"}
# Upload the file to the Cloudflare Image Service
echo "$file"
echo "$file_path"
curl --request POST https://api.cloudflare.com/client/v4/accounts/"$account_id"/images/v1 \
--header "Authorization: Bearer $api_token" \
--form "file=@$file" \
--form "id=$file_path"
done
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.