Skip to content

feat: Added support for Cloudflare R2 storage - #3938

Closed
tylersavery wants to merge 2 commits into
serverpod:mainfrom
tylersavery:main
Closed

tylersavery wants to merge 2 commits into
serverpod:mainfrom
tylersavery:main

Conversation

@tylersavery

Copy link
Copy Markdown

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_r2 which 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

import 'package:serverpod_cloud_storage_r2/serverpod_cloud_storage_r2.dart' as r2;

pod.addCloudStorage(r2.R2CloudStorage(
    serverpod: pod,
    storageId: 'public',
    public: true,
    region: 'auto',
    bucket: 'my-bucket',
    accountId: "cloudflare-account-id",
    publicHost: "https://mydomain.com",
  ));

The asset endpoint doesn't require any changes from what is in serverpod's docs.
The flutter app doesn't require any changes either from what is in serverpod's docs.

Thanks for considering this PR and I hope you're having a great time at Flutter & Friends!

@coderabbitai

coderabbitai Bot commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions

github-actions Bot commented Sep 1, 2025 •

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@tylersavery

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@tylersavery tylersavery changed the title Added support for Cloudflare R2 storage feat: Added support for Cloudflare R2 storage Sep 1, 2025
@SandPod

SandPod commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

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!

@tylersavery

Copy link
Copy Markdown
Author

Sounds great! Let me know if you have any q's once you have a chance to review.

@tananga

tananga commented Sep 3, 2025

Copy link
Copy Markdown

@tylersavery Thanks for your youtube video about this PR. I learned a lot how to contibute to serverpod myself. You are great🤘

@SandPod

SandPod commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

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.

@marcelomendoncasoares

Copy link
Copy Markdown
Collaborator

Closing this since R2 support was added with #4771.

@github-actions github-actions Bot locked and limited conversation to collaborators Jul 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants