Crates.io | qcos |
lib.rs | qcos |
version | |
source | src |
created_at | 2022-04-04 11:00:13.836921 |
updated_at | 2024-10-01 08:31:06.159921 |
description | Provide basic interface encapsulation of Tencent Cloud Object Storage (cos) |
homepage | |
repository | https://github.com/bujnlc8/qcos |
max_upload_size | |
id | 561933 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
本包提供腾讯云对象存储(cos) 基本的操作,包括bucket
创建及删除,对象的上传、下载、删除等。
上传文件支持以下特点:
支持文件直传,推荐 1GB 以下的文件
支持分块传输,设置分块大小和最大上传线程数量(基于 tokio::spawn)
支持显示上传进度条(需开启progress-bar
feature),上传方法名称加了_progress_bar
后缀与不显示进度条的方法区分
从0.1.9
版本之后,下载文件也支持显示进度条 🚀🚀🚀
use std::path::PathBuf;
use qcos::acl::{AclHeader, ObjectAcl};
use qcos::client::Client;
use qcos::objects::{mime, ErrNo};
#[tokio::main]
async fn main() {
let client = Client::new(
"Your secrect id",
"Your secrect key",
"Bucket name",
"Region",
);
let mut acl_header = AclHeader::new();
acl_header.insert_object_x_cos_acl(ObjectAcl::PublicRead);
let file_path = PathBuf::from("test.png");
let res = client.put_object(&file_path, "test.png", Some(mime::IMAGE_PNG), Some(acl_header)).await;
if res.error_no == ErrNo::SUCCESS {
println!("success");
} else {
println!("[{}]: {}", res.error_no, res.error_message);
}
// 分块上传,带进度条
#[cfg(feature = "progress-bar")]
let res = client
.clone()
.put_big_object_progress_bar(
&file_path,
"test.png",
None,
Some(qcos::objects::StorageClassEnum::ARCHIVE),
None,
Some(1024 * 1024),
None,
None,
)
.await;
// 下载文件到本地,启用10个线程,并开启进度条
#[cfg(feature = "progress-bar")]
let res = client
.get_object_progress_bar("Cargo.toml", "local_Cargo.toml", Some(10), None)
.await;
}
更多的例子请参考examples。
[dependencies]
qcos = "0.1"
如果需要开启显示进度条的方法:
[dependencies]
qcos = {version = "0.1", features=["progress-bar"]}