#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

#1150 in Web programming

34 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
~289K SLoC