COS
Tencent Cloud COS services support.
Capabilities
This service can be used to:
- stat
- read
- write
- create_dir
- delete
- copy
- rename
- list
- presign
- blocking
Configuration
root
: Set the work directory for backendbucket
: Set the container name for backendendpoint
: Customizable endpoint settingaccess_key_id
: Set the access_key_id for backend.secret_access_key
: Set the secret_access_key for backend.
You can refer to [CosBuilder
]'s docs for more information
Example
Via Builder
use anyhow::Result;
use opendal::services::Cos;
use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
// create backend builder
let mut builder = Cos::default();
// set the storage bucket for OpenDAL
builder.bucket("test");
// set the endpoint for OpenDAL
builder.endpoint("https://cos.ap-singapore.myqcloud.com");
// Set the access_key_id and secret_access_key.
//
// OpenDAL will try load credential from the env.
// If credential not set and no valid credential in env, OpenDAL will
// send request without signing like anonymous user.
builder.secret_id("secret_id");
builder.secret_key("secret_access_key");
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("endpoint".to_string(), "https://cos.ap-singapore.myqcloud.com".to_string());
map.insert("secret_id".to_string(), "secret_id".to_string());
map.insert("secret_key".to_string(), "secret_access_key".to_string());
let op: Operator = Operator::via_map(Scheme::Cos, map)?;
Ok(())
}
import { Operator } from "opendal";
async function main() {
const op = new Operator("cos", {
bucket: "test",
endpoint: "https://cos.ap-singapore.myqcloud.com",
secret_id: "secret_id",
secret_key: "secret_access_key",
});
}
import opendal
op = opendal.Operator("cos",
bucket="test",
endpoint="https://cos.ap-singapore.myqcloud.com",
secret_id="secret_id",
secret_key="secret_access_key",
)