Skip to main content

Connecting to your storage

Switching backends is a configuration change, not a code change. For the configuration keys of a specific service, see Services.

The binding bundles every service — there are no build flags. Once the binding is referenced, every backend is available.

Build an operator

From a scheme and dictionary

The first argument is the service scheme; configuration follows as a Dictionary<string, string> whose keys match the service's configuration fields:

using OpenDAL;

using var op = new Operator("s3", new Dictionary<string, string>
{
["bucket"] = "my-bucket",
["region"] = "us-east-1",
["endpoint"] = "https://s3.amazonaws.com",
});

A local filesystem operator roots every path under one directory:

using var fs = new Operator("fs", new Dictionary<string, string>
{
["root"] = "/tmp/opendal",
});

From a typed service config

Each service also has a strongly typed config class in OpenDAL.ServiceConfig. It is converted to the same key/value options internally, so the result is identical — pick this form for compile-time-checked, discoverable properties:

using OpenDAL;
using OpenDAL.ServiceConfig;

using var fs = new Operator(new FsServiceConfig
{
Root = "/tmp/opendal",
});

Available scheme names and their keys are defined by OpenDAL; see the Scheme reference and Services.

Credentials

Credentials are just more configuration keys. Set them in the dictionary (or on the typed config) — for example S3's access_key_id and secret_access_key:

using var op = new Operator("s3", new Dictionary<string, string>
{
["bucket"] = "my-bucket",
["region"] = "us-east-1",
["access_key_id"] = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID")!,
["secret_access_key"] = Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY")!,
});

Some services also load credentials from their platform's default sources (for S3, the standard AWS environment variables and profiles). See each service's page under Services for the exact keys and credential behavior.

Avoid hard-coding secrets in source. Read them from the environment or a secret manager and pass them in when you build the operator.

One operator per service and root

An operator maps to one service and one root path. To work with two buckets or two roots, build two operators — they are lightweight handles. Use Duplicate() to create another handle to the same backend configuration. Always dispose operators with using or an explicit Dispose().