R2 REST API support?

Hi there, I’m just curious that if R2 supports REST API access like S3. We have a use case where we implement concurrent S3 calls while uploading or downloading multiple files. Using REST works with Python’s asyncio module whereas Amazon’s Boto3 doesn’t.

To clarify, we are able to use Cloudflare’s S3 API compatibility features with Boto3. But when we switch to a REST API approach, S3 works but R2 doesn’t. I suppose there are specific headers that are required? I looked through the documentation by couldn’t find any info.

Thanks in advance for any pointers!

Can you provide the call and output showing the error? Please redact any pii info such as tokens. A screenshot would be helpful as well to see the issue better.

Thanks for looking into this! Here’s the headers of the PUT request we make:

headers = {
    'Authorization': 'AWS {R2_ACCESS_KEY}/Lu+W5bH+jQ6I=', 
    'Content-Type': 'application/octet-stream', 
    'Content-MD5': 'ZUujUcSgMi2x3jhTjpgYuw==', 
    'Date': 'Fri, 31 Mar 2023 14:28:32 GMT', 
    'Host': 'https://<ACCOUNT_ID>.r2.cloudflarestorage.com'

where the Lu+W5bH+jQ6I= bit is the REST signature computed according to AWS’s documentation here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html

The body of the request is just binary data that represents the content of the file we are trying to upload to R2.

We make this call using Python’s requests library:

        response = requests.put(

Any obvious mistakes here?

The response error message we got is:

(400, '<html>\r\n<head><title>400 Bad Request</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n<hr><center>cloudflare</center>\r\n</body>\r\n</html>\r\n')

Hello, have you find out what your problem is? We can’t use the API either. It always says we are not authorized. The signature is calculated like in your S3 link. .

By the way : I think in your request the error is, that there should be a “:” between the {R2_ACCES_KE} and the signature and not a “/” .

Hi! No unfortunately we have never been able to make it work. Thanks for pointing the encoding mishap - we’ll try it again. Our current solution is just to use Python’s multiprocess and run aws’s command line tool under the hood. Very inelegant.

I do wish Cloudflare publishes an example showing how REST API can be used with R2. Oh well…

Hello, were you able to get this to work?
I am attempting to upload a file, but even after trying to brute-force-guess what headers Cloudflare seems to want, I was unable to find out. Nor was i able to find anything about them in the documentation

Nevermind, after hours i was able to figure out that i can steal the request from the Postman example + use the aws s3 library for java

Ah thanks for the tip on stealing from postman lol.

Yeah using language specific sdks always worked.