Configure aws-sdk-net
for R2
You must generate an Access Key before getting started. All examples will utilize access_key_id
and access_key_secret
variables which represent the Access Key ID and Secret Access Key values you generated.
This example uses version 3 of the
aws-sdk-net package. You must pass in the R2 configuration credentials when instantiating your S3
service client:
Client setup
In this example, you will pass credentials explicitly to the IAmazonS3
initialization. If you wish, use a shared AWS credentials file or the SDK store in-line with other AWS SDKs. Refer to
Configure AWS credentials for more details.
List buckets and objects
The ListBucketsAsync and ListObjectsAsync methods can be used to list buckets under your account and the contents of those buckets respectively.
Upload and retrieve objects
The PutObjectAsync and GetObjectAsync methods can be used to upload objects and download objects from an R2 bucket respectively.
Generate presigned URLs
The
GetPreSignedURL method allows you to sign ahead of time, giving temporary access to a specific operation. In this case, presigning a PutObject
request for sdk-example/file.txt
.