#object-storage #cloud-storage #cos #tencent-cloud #tengxunyun

qcos

Provide basic interface encapsulation of Tencent Cloud Object Storage (cos)

14 releases

0.1.13 Oct 1, 2024
0.1.12 Aug 23, 2024
0.1.6 Oct 16, 2022
0.1.5 Apr 7, 2022

#1139 in Web programming

Download history 7/week @ 2024-07-13 8/week @ 2024-07-20 18/week @ 2024-07-27 367/week @ 2024-08-03 233/week @ 2024-08-10 169/week @ 2024-08-17 59/week @ 2024-08-24 12/week @ 2024-08-31 29/week @ 2024-09-07 86/week @ 2024-09-14 58/week @ 2024-09-21 196/week @ 2024-09-28 32/week @ 2024-10-05 18/week @ 2024-10-12 12/week @ 2024-10-19 4/week @ 2024-10-26

82 downloads per month
Used in qcloud

MIT license

94KB
2K SLoC

Crates.io qcos

腾讯云对象存储(COS) Rust

本包提供腾讯云对象存储(cos) 基本的操作,包括bucket创建及删除,对象的上传、下载、删除等。

上传文件支持以下特点:

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

  • 支持分块传输,设置分块大小和最大上传线程数量(基于 tokio::spawn)

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

0.1.9版本之后,下载文件也支持显示进度条 🚀🚀🚀

How to use

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

Installation

[dependencies]
qcos = "0.1"

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

[dependencies]
qcos = {version = "0.1", features=["progress-bar"]}

Dependencies

~9–21MB
~286K SLoC