Crate qiniu_objects_manager
source ·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
pub use qiniu_apis as apis;
pub use qiniu_apis::http_client::mime;
Modules
- 将所有 Trait 全部重新导出,方便统一导入
Structs
- 设置对象生命周期天数
- 批量操作
- 批量操作迭代器
- 批量操作流
- 七牛存储空间管理器
- 对象复制操作构建器
- 对象删除操作构建器
- 列举操作构建器
- 对象列举迭代器
- 对象列举流
- 修改对象生命周期构建器
- 修改对象元信息构建器
- 修改对象状态构建器
- 对象移动操作构建器
- 七牛对象管理器
- 七牛对象管理构建器
- 对象类型设置操作构建器
- 对象元信息获取操作构建器
- 对象解冻操作构建器
Enums
- 列举 API 版本
Traits
- 最大批量操作数获取接口
- 对象操作提供者接口