Skip to main content

Gcs

Google Cloud Storage Support

Capabilities

This service can be used to:

  • stat
  • read
  • write
  • create_dir
  • delete
  • copy
  • rename
  • list
  • scan
  • presign
  • blocking

Configuration

  • root: Set the work directory for backend
  • bucket: Set the container name for backend
  • endpoint: Customizable endpoint setting
  • credential: Credentials string for GCS service OAuth2 authentication
  • credential_path: Local path to credentials file for GCS service OAuth2 authentication
  • predefined_acl: Predefined ACL for GCS
  • default_storage_class: Default storage class for GCS

Refer to public API docs for more information.

Example

Via Builder

use anyhow::Result;
use opendal::services::Gcs;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
// create backend builder
let mut builder = Gcs::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 string of service account
builder.credential("service account credential");
// set the predefined ACL for GCS
builder.predefined_acl("publicRead");
// set the default storage class for GCS
builder.default_storage_class("STANDARD");

let op: Operator = Operator::new(builder)?.finish();
Ok(())
}

Via Config

use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("bucket".to_string(), "test".to_string());
map.insert("root".to_string(), "/path/to/dir".to_string());
map.insert("credential".to_string(), "authentication token".to_string());
map.insert("predefined_acl".to_string(), "publicRead".to_string());
map.insert("default_storage_class".to_string(), "STANDARD".to_string());

let op: Operator = Operator::via_map(Scheme::Gcs, map)?;
Ok(())
}