r2
is a library and command line interface for working with Cloudflare's R2 Storage.
r2 [command] [flags]
configure
— Configure R2 accesscp
— Copy an object from one R2 path to anotherhelp
— Help about any commandls
— List either all buckets or all objects in a bucketmb
— Create an R2 bucketmv
— Moves a local file or R2 object to another location locally or in R2.presign
— Generate a pre-signed URL for a Cloudflare R2 objectrb
— Remove an R2 bucketrm
— Remove an object from an R2 bucketsync
— Syncs directories and R2 prefixes.
-p, --profile
— R2 profile to use (default "default")-h, --help
— Help for any command
Help for any command can be obtained by running r2 help [command]
. For example:
# Help for the configure command
r2 help configure
The r2
library can be used to interact with R2 from within your Go application. All library code
exists in the pkg directory and is well documented.
Documentation may be found here.
Uploading a file to a bucket:
package main
import (
r2 "github.com/boatkit-io/r2/pkg"
)
func main() {
// Create client
config := r2.Config{
Profile: "default",
AccountID: "<ACCOUNT ID>",
AccessKeyID: "<ACCESS KEY ID>",
SecretAccessKey: "<SECRET ACCESS KEY>"
}
client := r2.Client(config)
// Connect to bucket
bucket := client.Bucket("my-bucket")
// Upload a file to the bucket
bucket.Upload("my-local-file.txt", "my-remote-file.txt")
}