cloudflare_r2_uploader 1.0.0

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

A Dart package for uploading files to Cloudflare R2 using AWS Signature Version 4. Supports progress tracking, automatic MIME detection, and returns the uploaded file URL.

📦 Cloudflare R2 Uploader

A simple Dart package to upload files directly to Cloudflare R2 using AWS Signature Version 4 signing. This package supports progress tracking, automatic MIME type detection, and returns the uploaded file URL on success.


✨ Features

  • ✅ Upload files to Cloudflare R2 buckets
  • ✅ AWS S3–compatible request signing
  • ✅ Automatic MIME type detection
  • ✅ Upload progress callback
  • ✅ Pure Dart (no Flutter dependency)

📥 Installation

Add this to your pubspec.yaml:

dependencies:
  cloudflare_r2_uploader: ^1.0.0
<!-- 
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages). 

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages). 
-->

⚙️ Parameters

ParameterTypeDescription
accountIdStringYour Cloudflare account ID
accessKeyIdStringCloudflare R2 Access Key ID
secretAccessKeyStringCloudflare R2 Secret Access Key
bucketNameStringName of the target bucket
regionString(Optional) R2 region, defaults to auto
fileBytesUint8ListFile content in bytes
fileNameStringName to store the file as
folderNameString?(Optional) Folder inside the bucket
onProgressFunction(double)(Optional) Upload progress callback

🛠️ Example with Progress Indicator

dart
await uploader.uploadFile( fileBytes: fileBytes, fileName: 'test.png', folderName: 'images', onProgress: (progress) { print('Progress: ${(progress * 100).toStringAsFixed(2)}%'); }, );

✅ Requirements

  • Cloudflare R2 account
  • R2 bucket created
  • Access Key & Secret Key generated from Cloudflare dashboard

🧪 Testing

You can write unit tests to mock HTTP requests and verify the AWS Signature v4 signing logic.


📌 Notes

  • Ensure your Cloudflare R2 bucket permissions allow PUT requests.
  • This package signs each request securely using AWS Signature Version 4.

📄 License

MIT License. See the LICENSE file for details.


💡 Contributions & Issues

Pull requests are welcome!

For issues, please open a GitHub issue describing the problem.