Class R2Settings
- Namespace
- Cloudflare.NET.R2.Configuration
- Assembly
- Cloudflare.NET.R2.dll
Represents R2-specific settings for the S3-compatible API, typically loaded from configuration.
public class R2Settings
- Inheritance
-
R2Settings
- Inherited Members
Fields
DefaultRegion
The default R2 region. Cloudflare R2 uses "auto" as the region for all operations.
public const string DefaultRegion = "auto"
Field Value
Properties
AccessKeyId
The R2 Access Key ID (from user secrets or environment variables). Required.
public string AccessKeyId { get; set; }
Property Value
EndpointUrl
The R2 S3 API endpoint URL. When set, must contain a format placeholder {0} for the Account ID.
public string? EndpointUrl { get; set; }
Property Value
Remarks
When null or empty (the default), the endpoint is automatically computed from
Jurisdiction:
- Default:
https://{account_id}.r2.cloudflarestorage.com - EU:
https://{account_id}.eu.r2.cloudflarestorage.com - FedRAMP:
https://{account_id}.fedramp.r2.cloudflarestorage.com - US:
https://{account_id}.us.r2.cloudflarestorage.com
When explicitly set, this value takes precedence over Jurisdiction. This allows for custom endpoint configurations or testing scenarios.
Jurisdiction
The jurisdiction for this R2 client configuration. Determines which S3 endpoint to use when EndpointUrl is not explicitly set.
public R2Jurisdiction Jurisdiction { get; set; }
Property Value
Examples
Configuration via appsettings.json:
{
"R2": {
"AccessKeyId": "...",
"SecretAccessKey": "...",
"Jurisdiction": "eu"
}
}
Remarks
Defaults to Default (no jurisdictional restriction),
which uses the global endpoint: https://{account_id}.r2.cloudflarestorage.com
When set to a specific jurisdiction (e.g., EuropeanUnion), the S3 endpoint URL is automatically computed to use the jurisdiction-specific endpoint.
If EndpointUrl is explicitly set, it takes precedence over the jurisdiction-based endpoint calculation.
Region
The R2 region. Defaults to "auto", which is the standard region for Cloudflare R2.
public string Region { get; set; }
Property Value
SecretAccessKey
The R2 Secret Access Key (from user secrets or environment variables). Required.
public string SecretAccessKey { get; set; }
Property Value
Methods
GetEffectiveEndpointUrl(string)
Gets the effective endpoint URL for this configuration, computing from jurisdiction if not explicitly set.
public string GetEffectiveEndpointUrl(string accountId)
Parameters
accountIdstringThe Cloudflare account ID to substitute into the endpoint URL.
Returns
- string
The fully-formed S3 endpoint URL ready for use with the AWS SDK.
Remarks
Resolution order:
-
If EndpointUrl is set, use it with
{0}replaced by account ID. - Otherwise, compute from Jurisdiction using GetS3EndpointUrl(string).
Exceptions
- ArgumentException
Thrown when
accountIdis null or whitespace.
GetEndpointUrlForJurisdiction(string, R2Jurisdiction)
Gets the endpoint URL for a specific jurisdiction override, ignoring EndpointUrl.
public static string GetEndpointUrlForJurisdiction(string accountId, R2Jurisdiction jurisdictionOverride)
Parameters
accountIdstringThe Cloudflare account ID.
jurisdictionOverrideR2JurisdictionThe jurisdiction to use instead of Jurisdiction.
Returns
- string
The fully-formed S3 endpoint URL for the specified jurisdiction.
Remarks
This method always computes the endpoint from the jurisdiction parameter, ignoring both EndpointUrl and Jurisdiction. Used by IR2ClientFactory when creating jurisdiction-specific clients with GetClient(R2Jurisdiction) or GetClient(string, R2Jurisdiction).
Exceptions
- ArgumentException
Thrown when
accountIdis null or whitespace.