Expand description

qiniu-objects-manager

七牛对象管理

基于 qiniu-apis 提供针对七牛对象的管理功能 (同时提供阻塞客户端和异步客户端,异步客户端则需要启用 async 功能), 主要负责七牛对象的列举和操作。

功能描述

async

启用异步接口。

ureq

导入 qiniu-ureq 作为 HTTP 客户端。

isahc

导入 qiniu-isahc 作为 HTTP 客户端。

reqwest

导入 qiniu-reqwest 作为 HTTP 客户端。

c_ares

启用 c-ares 库作为 DNS 解析器。

trust_dns

启用 trust-dns 库作为 DNS 解析器。

dns-over-https

启用 trust-dns 库作为 DNS 解析器,并使用 DOH 协议。

dns-over-tls

启用 trust-dns 库作为 DNS 解析器,并使用 DOT 协议。

代码示例

对象元信息获取
阻塞代码示例
use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");

let response = bucket.stat_object("test-key").call()?;
let object = response.into_body();
println!("fsize: {}", object.get_size_as_u64());
println!("hash: {}", object.get_hash_as_str());
println!("mime_type: {}", object.get_mime_type_as_str());
异步代码示例
use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");

let response = bucket.stat_object("test-key").async_call().await?;
let object = response.into_body();
println!("fsize: {}", object.get_size_as_u64());
println!("hash: {}", object.get_hash_as_str());
println!("mime_type: {}", object.get_mime_type_as_str());
对象批量元信息获取
阻塞代码示例
use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager, OperationProvider};

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut ops = bucket.batch_ops();
ops.add_operation(bucket.stat_object("test-file-1"));
ops.add_operation(bucket.stat_object("test-file-2"));
ops.add_operation(bucket.stat_object("test-file-3"));
ops.add_operation(bucket.stat_object("test-file-4"));
ops.add_operation(bucket.stat_object("test-file-5"));
let mut iter = ops.call();
while let Some(object) = iter.next() {
    let object = object?;
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}
异步代码示例
use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager, OperationProvider};
use futures::stream::TryStreamExt;

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut ops = bucket.batch_ops();
ops.add_operation(bucket.stat_object("test-file-1"));
ops.add_operation(bucket.stat_object("test-file-2"));
ops.add_operation(bucket.stat_object("test-file-3"));
ops.add_operation(bucket.stat_object("test-file-4"));
ops.add_operation(bucket.stat_object("test-file-5"));
let mut stream = ops.async_call();
while let Some(object) = stream.try_next().await? {
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}
对象列举
阻塞代码示例
use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut iter = bucket.list().iter();
while let Some(object) = iter.next() {
    let object = object?;
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}
异步代码示例
use qiniu_objects_manager::{apis::credential::Credential, ObjectsManager};
use futures::stream::TryStreamExt;

let credential = Credential::new("abcdefghklmnopq", "1234567890");
let object_manager = ObjectsManager::new(credential);
let bucket = object_manager.bucket("test-bucket");
let mut stream = bucket.list().stream();
while let Some(object) = stream.try_next().await? {
    println!("fsize: {:?}", object.get_size_as_u64());
    println!("hash: {:?}", object.get_hash_as_str());
    println!("mime_type: {:?}", object.get_mime_type_as_str());
}

Re-exports

Modules

  • 将所有 Trait 全部重新导出,方便统一导入

Structs

Enums

Traits