cloudflare_r2_uploader 1.0.0
cloudflare_r2_uploader: ^1.0.0 copied to clipboard
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
| Parameter | Type | Description |
|---|---|---|
accountId |
String |
Your Cloudflare account ID |
accessKeyId |
String |
Cloudflare R2 Access Key ID |
secretAccessKey |
String |
Cloudflare R2 Secret Access Key |
bucketName |
String |
Name of the target bucket |
region |
String |
(Optional) R2 region, defaults to auto |
fileBytes |
Uint8List |
File content in bytes |
fileName |
String |
Name to store the file as |
folderName |
String? |
(Optional) Folder inside the bucket |
onProgress |
Function(double) |
(Optional) Upload progress callback |
π οΈ Example with Progress Indicator #
dartawait 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.