Repository navigation
feat: Added support for Cloudflare R2 storage - #3938
tylersavery wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Hey @tylersavery 👋 Thanks for taking the time to contribute to Serverpod! 🎉 The storage interface is something we are looking to rework, so we are happy for all initiatives that improve this experience. I hope that we will be able to take a look at this PR fairly soon, but we do have a couple of higher priority issues we are battling at the moment! |
|
Sounds great! Let me know if you have any q's once you have a chance to review. |
|
@tylersavery Thanks for your youtube video about this PR. I learned a lot how to contibute to serverpod myself. You are great🤘 |
|
Hey @tylersavery! Sorry for the delay in getting back to you on this one. Things have been quite busy as we’re closing in on the first RC cut of Serverpod 3. Once that’s out, the team will finally have some development bandwidth freed up. The main reason we haven’t done a quick review of this PR yet is that we’re still uncertain about the long-term direction for the storage integration. We’ve identified a few bugs that we suspect could all be addressed with some dedicated engineering effort, and our current thinking is to consolidate into a single storage package that supports multiple integrations, rather than maintaining separate ones. Given that the direction is still up in the air, we didn’t feel comfortable merging and committing to maintaining another integration package just yet. Really appreciate your patience. We’ll revisit this once we have more clarity on where the storage module is headed. |
|
Closing this since R2 support was added with #4771. |
Hi Serverpod team!
I wanted to create support for Cloudflare R2 as a storage backend. My first attempt was just to allow the endpoint to be overridden since I was under the impression the two APIs were basically interchangeable, but I learned that Cloudflare uses PUT requests while S3 allows for POST (which is what the s3 integration uses).
My next attempt (which I'm PRing with here) was to create a new integration called
serverpod_cloud_storage_r2which uses the same pattern as the s3 integration as well as the AWS same library (amazon_cognito_identity_dart_2) for identity. It was important to me that no new packages would be required for this implementation.Additionally, i needed to modify the serverpod_client FileUploader class to optionally allow overriding the method when uploading the file to the bucket. It is able to parse this from the upload description but falls back to POST by default.
In doing this, I noticed that the mimetypes were always application/octet-stream (I believe for S3 as well) so I've included a helper function that will detect the mime based on the extension of the file. I did not incorporate this change with the other two integrations.
In the spirit of following the patterns of the s3 integration, I did not add tests. I assume this was purposefully omitted previously because it would require an S3 bucket / credentials for the tests to run. Would be happy to do so (I'd just need a bit of guidance on the best way to manage keys and such for this and I'd just follow the same test cases as the database upload).
Additionally, I believe this new integration will also support users who want to use other s3 alternatives such as minos or hetzner because they also use PUT requests. I haven't taken the time to test these out yet but I expect it should work – or at least be very close.
Here is an example implementation. See the integration's readme for more details!
server.dart
Thanks for considering this PR and I hope you're having a great time at Flutter & Friends!