Skip to content

Commit

Permalink
支持上传进度条
Browse files Browse the repository at this point in the history
  • Loading branch information
bujnlc8 committed Aug 7, 2024
1 parent e341e33 commit a21431e
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/qcos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Lint
run: cargo clippy
run: cargo clippy --features progress-bar
- name: Build
run: cargo build --verbose
run: cargo build --verbose --features progress-bar
- name: Run tests
run: cargo test --verbose -- --nocapture
run: cargo test --features progress-bar --verbose -- --nocapture
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "qcos"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["bujnlc8 <[email protected]>"]
description = "provide basic interface encapsulation of Tencent Cloud Object Storage (cos)"
Expand All @@ -21,6 +21,12 @@ bytes ="1.7.1"
quick-xml = {version = "0.36.1", features = ["serialize"]}
async-trait = "0.1.81"
tokio = { version = "1.39.2", features = ["full"]}
indicatif = { version = "0.17.8", optional = true }
futures-util = { version = "0.3.30", optional = true }
tokio-util = {version = "0.7.11", optional = true}

[dev-dependencies]
tokio = { version = "1.39.2", features = ["full"]}

[features]
progress-bar = ["indicatif", "futures-util", "tokio-util"]
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

**异步版本** `async`/`await`

本包提供腾讯云对象存储(cos) 基本的操作,包括`bucket`创建及删除,对象的上传(支持分块传输,设置分块大小及上传线程数量)、下载、删除等。
本包提供腾讯云对象存储(cos) 基本的操作,包括`bucket`创建及删除,对象的上传、下载、删除等。

上传文件支持以下特点:

- 支持文件直传,推荐 1GB 以下的文件

- 支持分块传输,设置分块大小和最大上传线程数量

- 支持显示上传进度条(需开启`progress-bar` feature),上传方法名称加了`_progress_bar`后缀与不显示进度条的方法区分

# How to use

Expand All @@ -28,6 +36,21 @@ async fn main() {
} else {
println!("{}", res.error_message);
}
// 分块上传,带进度条
#[cfg(feature = "progress-bar")]
let res = client
.clone()
.put_big_object_progress_bar(
"Cargo.toml",
"Cargo.toml",
Some(mime::TEXT_PLAIN_UTF_8),
Some(qcos::objects::StorageClassEnum::ARCHIVE),
None,
Some(1024 * 1024),
None,
None,
)
.await;
}

```
Expand All @@ -42,5 +65,12 @@ insert into your project's cargo.toml block next line

```
[dependencies]
qcos = "0.1.7"
qcos = "0.1.8"
```

如果需要开启显示进度条的方法:

```
[dependencies]
qcos = {version = "0.1.8", features=["progress-bar"]}
```
23 changes: 22 additions & 1 deletion examples/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() {
} else {
println!("{}", res.error_message);
}
// 分块传输
// 分块上传
let res = client
.clone()
.put_big_object(
Expand All @@ -61,6 +61,27 @@ async fn main() {
} else {
println!("{}", res.error_message);
}
// 分块上传,带进度条
#[cfg(feature = "progress-bar")]
let res = client
.clone()
.put_big_object_progress_bar(
"Cargo.toml",
"Cargo.toml",
Some(mime::TEXT_PLAIN_UTF_8),
Some(qcos::objects::StorageClassEnum::ARCHIVE),
None,
Some(1024 * 1024),
None,
None,
)
.await;
#[cfg(feature = "progress-bar")]
if res.error_no == ErrNo::SUCCESS {
println!("SUCCESS");
} else {
println!("{}", res.error_message);
}
// 直接上传二进制流
let res = client
.put_object_binary(
Expand Down
1 change: 1 addition & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::acl::AclHeader;
use crate::request::Response;
use crate::signer::Signer;

/// 接口请求Client
/// # Examples
/// ```
Expand Down
Loading

0 comments on commit a21431e

Please sign in to comment.