Expand description
Google Cloud Storage support for OpenDAL.
Configuration
root
: Set the work directory for backendbucket
: Set the container name for backendendpoint
: Customizable endpoint settingcredentials
: Credential string for GCS OAuth2
You can refer to Builder
’s docs for more information
Environment
OPENDAL_GCS_ENDPOINT
optionalOPENDAL_GCS_BUCKET
requiredOPENDAL_GCS_ROOT
optionalOPENDAL_GCS_CREDENTIAL
required
Example
Initiate via environment variables
Set environment correctly:
export OPENDAL_GCS_ENDPOINT=https://storage.googleapis.com # by default
export OPENDAL_GCS_BUCKET=test
export OPENDAL_GCS_ROOT=/path/to/dir/ # if not set, will be seen as "/"
export OPENDAL_GCS_CREDENTIAL=secret_oauth2_credential
use anyhow::Result;
use opendal::Object;
use opendal::Operator;
use opendal::Scheme;
#[tokio::main]
async fn main() -> Result<()> {
let op: Operator = Operator::from_env(Scheme::Gcs)?;
// create an object handler to start operation on it.
let _op: Object = op.object("test_file");
Ok(())
}
Via Builder
use anyhow::Result;
use opendal::services::gcs;
use opendal::Object;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// create backend builder
let mut builder = gcs::Builder::default();
// set the storage bucket for OpenDAL
builder.bucket("test");
// set the working directory root for GCS
// all operations will happen within it
builder.root("/path/to/dir");
// set the credentials for GCS OAUTH2 authentication
builder.credential("authentication token");
let op: Operator = Operator::new(builder.build()?);
let _: Object = op.object("test_file");
Ok(())
}
Structs
GCS storage backend builder