Connecting CBCloudDrive to Amazon S3 and Compatible Services
Requirements: CBFSCloud
This article explains how to configure CBCloudDrive to connect to Amazon S3 or any S3-compatible object storage service. For a general overview of how the component works, see Getting Started with the CBCloudDrive Component.
Contents
Prerequisites
Amazon S3 and S3-compatible connections require the local cache to be fully enabled. Before calling Mount:
- CacheDirectory must be set to a valid, writable local directory path.
- CacheEnabledForRead must be true (this is the default).
Without these, the component will not be able to mount an Amazon S3 or S3-compatible drive.
Connection Parameters
Set ConnectionType to ctS3 and build a ConnectionString using the parameters below.
Required
| Parameter | Description |
|---|---|
| RemoteRoot | The S3-style path to use as the root of the mounted drive. The first path segment must be the bucket name (e.g., /my-bucket). Additional segments are treated as object key prefixes (e.g., /my-bucket/folder/subfolder). |
| AccessKey | The access key for authentication. Not required when using anonymous, profile, or EC2 role authentication. |
| SecretKey | The secret key for authentication. Not required when using anonymous, profile, or EC2 role authentication. |
Optional
| Parameter | Description |
|---|---|
| Provider | The S3-compatible service to connect to. Defaults to AMAZONS3. See the provider list below. |
| Region | The region to make requests against. Defaults vary by provider. |
| UseVirtualHosting | Whether to use virtual-hosted-style URLs (e.g., https://my-bucket.s3.amazonaws.com/object). Defaults to true. Set to false to use path-style URLs instead. |
| Timeout | Timeout in seconds for remote operations. |
The Provider parameter accepts the following values:
| Value | Service |
|---|---|
| AMAZONS3 (default) | Amazon S3 |
| DIGITALOCEAN | DigitalOcean Spaces |
| GOOGLESTORAGE | Google Cloud Storage |
| WASABI | Wasabi |
| BACKBLAZEB2 | Backblaze B2 |
| HUAWEI | Huawei Cloud Object Storage |
| ALIBABA | Alibaba Cloud Object Storage |
| IBM | IBM Cloud Object Storage |
| ORACLE | Oracle Cloud Object Storage |
| LINODE | Linode Object Storage |
| CLOUDFLARER2 | Cloudflare R2 |
| SEAGATELYVECLOUD | Seagate Lyve Cloud |
| OORTDSS | Oort DSS |
| TENCENT | Tencent Cloud Object Storage |
| CUSTOM | Custom S3-compatible endpoint |
Authentication
Access Key and Secret Key
The most common authentication method. Set the AccessKey and SecretKey parameters in the connection string.
drive.ConnectionType = CBCloudDriveConnectionTypes.ctS3;
drive.ConnectionString = "RemoteRoot=/my-bucket;AccessKey=MYACCESSKEY;SecretKey=MYSECRETKEY;";
AWS Credentials Profile
To load credentials from an AWS credentials file instead of specifying them directly, set UseAWSProfile to true. By default the component reads from the default profile at the standard credentials file location (~/.aws/ on Linux/macOS, %USERPROFILE%.aws</var> on Windows). Use AWSProfile to specify a different profile name, and AWSProfileDir to specify a different directory.
drive.ConnectionString = "RemoteRoot=/my-bucket;UseAWSProfile=true;AWSProfile=my-profile;";
EC2 Role Credentials
When running on an EC2 instance, the component can retrieve temporary credentials automatically from the instance metadata service (IMDS). Set UseEC2RoleCredentials to true; no access key or secret key is needed. IMDSv2 is used by default.
drive.ConnectionString = "RemoteRoot=/my-bucket;UseEC2RoleCredentials=true;";
Anonymous
To access publicly readable resources without credentials, set UseAnonymousAuthentication to true.
drive.ConnectionString = "RemoteRoot=/my-public-bucket;UseAnonymousAuthentication=true;";
Provider-Specific Notes
Cloudflare R2
Cloudflare R2 requires the AccountId parameter, which can be found in the Cloudflare dashboard under R2 Object Storage.
drive.ConnectionString = "RemoteRoot=/my-bucket;Provider=CLOUDFLARER2;AccountId=MY-ACCOUNT-ID;"
+ "AccessKey=MYACCESSKEY;SecretKey=MYSECRETKEY;";
Oracle Cloud Object Storage
Oracle Cloud Object Storage requires the OracleNamespace parameter. The namespace is the unique top-level container for all Oracle Cloud Object Storage buckets in a tenancy, and can be found in the Oracle Cloud Console under Object Storage & Archive Storage > Buckets.
drive.ConnectionString = "RemoteRoot=/my-bucket;Provider=ORACLE;OracleNamespace=MY-NAMESPACE;"
+ "AccessKey=MYACCESSKEY;SecretKey=MYSECRETKEY;";
Custom Providers
For any S3-compatible service not listed above, set Provider to CUSTOM and provide the base endpoint URL via the URL parameter. If the URL contains a %region% token, it will be replaced with the value of the Region parameter at runtime.
drive.ConnectionString = "RemoteRoot=/my-bucket;Provider=CUSTOM;URL=https://s3.my-provider.com;"
+ "AccessKey=MYACCESSKEY;SecretKey=MYSECRETKEY;";
Full Example
using callback.CBFSCloud;
CBCloudDrive drive = new CBCloudDrive();
// 1. Install the driver if needed
drive.ProductGUID = "{YOUR-PRODUCT-GUID}";
if (drive.GetDriverStatus() == 0) {
int result = drive.Install("/path/to/cbfs.cab");
if (result != 0) {
Console.WriteLine("Reboot required to complete driver installation.");
return;
}
}
// 2. Configure the Amazon S3 connection
drive.ConnectionType = CBCloudDriveConnectionTypes.ctS3;
drive.ConnectionString = "RemoteRoot=/my-bucket;"
+ "Provider=AMAZONS3;"
+ "Region=us-east-1;"
+ "AccessKey=MYACCESSKEY;"
+ "SecretKey=MYSECRETKEY;";
// 3. Configure the cache (required for S3-compatible connections)
drive.CacheDirectory = @"C:\my-app\cache";
// CacheEnabledForRead defaults to true
// 4. Mount the drive
drive.DriveName = "S3 Drive";
string mountPoint = drive.Mount("");
Console.WriteLine("Drive mounted at: " + mountPoint);
// 5. Unmount when done
drive.Unmount();
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@callback.com.