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 backendbucket
: Set the container name for backendendpoint
: Customizable endpoint settingcredential
: Credentials string for GCS service OAuth2 authenticationcredential_path
: Local path to credentials file for GCS service OAuth2 authenticationpredefined_acl
: Predefined ACL for GCSdefault_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
- Rust
- Node.js
- Python
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(())
}
import { Operator } from "opendal";
async function main() {
const op = new Operator("gcs", {
bucket: "test",
root: "/path/to/dir",
credential: "authentication token",
predefined_acl: "publicRead",
default_storage_class: "STANDARD",
});
}
import opendal
op = opendal.Operator("gcs",
bucket="test",
root="/path/to/dir",
credential="authentication token",
predefined_acl="publicRead",
default_storage_class="STANDARD",
)