PutObjectAsync() not working for R2 with AWS S3 .NET SDK

I’m trying to upload an object to Cloudflare R2 by using below code which uses AWS S3 SDK, but it gives me {“The remote server returned an error: (501) Not Implemented.”} exception, Error message was “STREAMING-AWS4-HMAC-SHA256-PAYLOAD not implemented”. Can anyone give me a sample to upload object Cloud-flare R2 by using AWS S3 .NET SDK

var config = new AmazonS3Config
                    {
                        ServiceURL = "**************************.r2.cloudflarestorage.com",
                        ForcePathStyle = true
                    };

                    var s3Client = new AmazonS3Client(accesskey, secretkey, config);

                    var request = new PutObjectRequest
                    {
                        BucketName = bucketName,
                        Key = $"{file.FileName}",
                        FilePath = filePath,
                    };

                    var response = await s3Client.PutObjectAsync(request);

Hello there!

Check here:
S3 API · Cloudflare R2 docs and our examples:
Examples · Cloudflare R2 docs

The most common tips to fix the 501 error can be found here:

Hope that it helps!

Take care!

There is no example available for .NET on https://developers.cloudflare.com/r2/examples/
However I solved the problem by the sample given by KianNH on https://github.com/cloudflare/cloudflare-docs/issues/4683

If anyone facing same issue, just use this “DisablePayloadSigning = true” in PutObjectRequest to disable sigv4 streaming

1 Like