bujnlc8 / qcos

腾讯云对象存储(COS) Rust
MIT License
17 stars 6 forks source link

不是内存对象 #6

Closed YenHarvey closed 1 month ago

YenHarvey commented 1 month ago

这是我的代码,key id等配置我确认了,没有问题的,设备Macbook M1 OS:Sequoia 15.0

use qcos::acl::{AclHeader, ObjectAcl};
use qcos::client::Client;
use qcos::objects::{mime, ErrNo};
use std::path::PathBuf;

#[tokio::main]
async fn main() {
    dotenv::dotenv().ok();

    let secret_id = std::env::var("TENCENT_SECRET_ID").unwrap();
    let secret_key = std::env::var("TENCENT_SECRET_KEY").unwrap();
    let bucket_name = std::env::var("TENCENT_COS_BUCKET").unwrap();
    let region = std::env::var("TENCENT_COS_REGION").unwrap();

    let client = Client::new(secret_id, secret_key, bucket_name, region);

    println!("client: {:?}", client);

    let mut acl_header = AclHeader::new();
    acl_header.insert_object_x_cos_acl(ObjectAcl::PublicRead);
    let file_path = PathBuf::from("/Users/xx/Downloads/upload_test/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_message);
    }
}

运行报错: ╭─    ~/Dow/upload_test  on   master ?6 ─ ✔  base   at 17:33:47  ─╮ ╰─ cargo run ─╯ Compiling upload_test v0.1.0 (/Users/cherrypeel/Downloads/upload_test) Finished dev profile [unoptimized + debuginfo] target(s) in 1.10s Running target/debug/upload_test 不是内存对象

bujnlc8 commented 1 month ago

rust 版本是多少,我手上没有aarch64架构的mac,最新的nightly版本在mbp 2020和linux是没有问题

YenHarvey commented 1 month ago

rust 版本是多少,我手上没有aarch64架构的mac,最新的nightly版本在mbp 2020和linux是没有问题

这是我的rust版本: rustc 1.81.0 (eeb90cda1 2024-09-04)

我在我的mac和服务器上测试都报这个错,后来稍微改了下倒是可以用了。

    pub async fn put_object(
        &self,
        file_path: &PathBuf,
        key: &str,
        content_type: Option<mime::Mime>,
        acl_header: Option<acl::AclHeader>,
    ) -> Response {
        let buf = match tokio::fs::read(file_path).await {
            Ok(buf) => buf,
            Err(e) => {
                return Response::new(
                    ErrNo::IO,
                    format!("读取文件失败: {:?}, {}", file_path, e),
                    Default::default(),
                )
            }
        };

        self.put_object_binary(buf, key, content_type, acl_header)
            .await
    }
bujnlc8 commented 1 month ago

0.1.13 已修复,非常感谢 @YenHarvey

YenHarvey commented 1 month ago

0.1.13 已修复,非常感谢 @YenHarvey

好的,应该的 :)