pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub fn new( secrect_id: impl Into<String>, secrect_key: impl Into<String>, security_token: Option<String>, bucket: impl Into<String>, region: impl Into<String>, ) -> Self
pub fn get_host(&self) -> String
pub fn get_secrect_key(&self) -> &str
pub fn get_secrect_id(&self) -> &str
pub fn gen_common_headers(&self) -> HashMap<String, String>
pub fn get_full_url_from_path(&self, path: &str) -> String
pub fn get_path_from_object_key(&self, key: &str) -> String
pub fn get_host_for_bucket_query(&self) -> String
pub fn get_headers_with_auth( &self, method: &str, url_path: &str, acl_header: Option<&AclHeader>, origin_headers: Option<HashMap<String, String>>, query: Option<&HashMap<String, String>>, ) -> HashMap<String, String>
pub fn make_response(&self, resp: Result<Response, Response>) -> Response
Trait Implementations§
Source§impl Bucket for Client
impl Bucket for Client
Source§fn put_bucket<'life0, 'life1, 'async_trait>(
&'life0 self,
acl_header: Option<&'life1 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn put_bucket<'life0, 'life1, 'async_trait>(
&'life0 self,
acl_header: Option<&'life1 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
创建一个存储桶 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::bucket::Bucket;
use tencent_qcloud_cos_rs::acl::{AclHeader, BucketAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_bucket_x_cos_acl(BucketAcl::PublicRead);
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.put_bucket(Some(&acl_header)).await;
assert!(res.error_message.contains("403"));
};Source§fn delete_bucket<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete_bucket<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
删除指定的存储桶。该 API 的请求者需要对存储桶有写入权限。 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::bucket::Bucket;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.delete_bucket().await;
assert!(res.error_message.contains("403"));
};Source§fn list_objects<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
delimiter: &'life2 str,
encoding_type: &'life3 str,
marker: &'life4 str,
max_keys: i32,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn list_objects<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
prefix: &'life1 str,
delimiter: &'life2 str,
encoding_type: &'life3 str,
marker: &'life4 str,
max_keys: i32,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
列出该存储桶内的部分或者全部对象。该 API 的请求者需要对存储桶有读取权限。 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::bucket::Bucket;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.list_objects("prefix", "", "", "/", 100).await;
assert!(res.error_message.contains("403"));
};Source§fn check_bucket<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn check_bucket<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
确认该存储桶是否存在,是否有权限访问
官网文档
存储桶存在且有读取权限,返回 SUCCESS
无存储桶读取权限,返回 ErrNo::STATUS, error_message包含403。
存储桶不存在,返回 ErrNo::STATUS, error_message包含404。
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::bucket::Bucket;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.check_bucket().await;
assert!(res.error_message.contains("403"));
};Source§fn put_bucket_acl<'life0, 'life1, 'async_trait>(
&'life0 self,
acl_header: &'life1 AclHeader,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn put_bucket_acl<'life0, 'life1, 'async_trait>(
&'life0 self,
acl_header: &'life1 AclHeader,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
写入存储桶的访问控制列表 官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::bucket::Bucket;
use tencent_qcloud_cos_rs::acl::{AclHeader, BucketAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_bucket_x_cos_acl(BucketAcl::PublicRead);
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.put_bucket(Some(&acl_header)).await;
assert!(res.error_message.contains("403"));
};Source§impl Objects for Client
impl Objects for Client
Source§fn put_object<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
file_path: &'life1 str,
key: &'life2 str,
content_type: Mime,
acl_header: Option<&'life3 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn put_object<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
file_path: &'life1 str,
key: &'life2 str,
content_type: Mime,
acl_header: Option<&'life3 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
上传本地小文件 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::objects::Objects;
use mime;
use tencent_qcloud_cos_rs::acl::{AclHeader, ObjectAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_object_x_cos_acl(ObjectAcl::AuthenticatedRead);
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.put_object("Cargo.toml", "Cargo.toml", mime::TEXT_PLAIN_UTF_8, Some(&acl_header)).await;
assert!(res.error_message.contains("403"));
};Source§fn put_big_object<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
file_path: &'life1 str,
key: &'life2 str,
content_type: Mime,
storage_class: &'life3 str,
acl_header: Option<&'life4 AclHeader>,
part_size: u64,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn put_big_object<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
file_path: &'life1 str,
key: &'life2 str,
content_type: Mime,
storage_class: &'life3 str,
acl_header: Option<&'life4 AclHeader>,
part_size: u64,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
上传本地大文件 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::objects::Objects;
use mime;
use tencent_qcloud_cos_rs::acl::{AclHeader, ObjectAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_object_x_cos_acl(ObjectAcl::AuthenticatedRead);
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
// 分块传输
let res = client.put_big_object("Cargo.toml","Cargo.toml", mime::TEXT_PLAIN_UTF_8, "ARCHIVE", Some(&acl_header), 1024 * 1024 * 100).await;
assert!(res.error_message.contains("403"));
};Source§fn put_object_binary<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
file: T,
key: &'life1 str,
content_type: Mime,
acl_header: Option<&'life2 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
fn put_object_binary<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, file: T, key: &'life1 str, content_type: Mime, acl_header: Option<&'life2 AclHeader>, ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
上传二进制流 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::objects::Objects;
use mime;
use tencent_qcloud_cos_rs::acl::{AclHeader, ObjectAcl};
async {
let mut acl_header = AclHeader::new();
acl_header.insert_object_x_cos_acl(ObjectAcl::AuthenticatedRead);
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let buffer = std::fs::read("Cargo.toml").unwrap();
let res = client.put_object_binary(buffer, "Cargo.toml", mime::TEXT_PLAIN_UTF_8, Some(&acl_header)).await;
assert!(res.error_message.contains("403"));
};Source§fn delete_object<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete_object<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
删除文件 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::objects::Objects;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.delete_object("Cargo.toml").await;
assert!(res.error_message.contains("403"))
};Source§fn get_object_binary<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_object_binary<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
下载文件二进制流 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::objects::Objects;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.get_object_binary("Cargo.toml").await;
assert!(res.error_message.contains("403"));
};Source§fn get_object<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
file_name: &'life2 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_object<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
file_name: &'life2 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
下载文件到本地 见官网文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::objects::Objects;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let res = client.get_object("Cargo.toml", "Cargo.toml").await;
assert!(res.error_message.contains("403"));
};Source§fn put_object_get_upload_id<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
key: &'life1 str,
content_type: &'life2 Mime,
storage_class: &'life3 str,
acl_header: Option<&'life4 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn put_object_get_upload_id<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
key: &'life1 str,
content_type: &'life2 Mime,
storage_class: &'life3 str,
acl_header: Option<&'life4 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
请求实现初始化分块上传,成功执行此请求后将返回 UploadId,用于后续的 Upload Part 请求 官网文档
Source§fn put_object_part<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
key: &'life1 str,
upload_id: &'life2 str,
part_number: u64,
body: Vec<u8>,
content_type: &'life3 Mime,
acl_header: Option<&'life4 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn put_object_part<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
key: &'life1 str,
upload_id: &'life2 str,
part_number: u64,
body: Vec<u8>,
content_type: &'life3 Mime,
acl_header: Option<&'life4 AclHeader>,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
分块上传文件 官网文档
Source§fn put_object_complete_part<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
key: &'life1 str,
etag_map: &'life2 HashMap<u64, String>,
upload_id: &'life3 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn put_object_complete_part<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
key: &'life1 str,
etag_map: &'life2 HashMap<u64, String>,
upload_id: &'life3 str,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
完成分块上传 官网文档
Source§impl Service for Client
impl Service for Client
Source§fn get_bucket_list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_bucket_list<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
查询请求者名下的所有存储桶列表或特定地域下的存储桶列表 见文档
§Examples
use tencent_qcloud_cos_rs::client::Client;
use tencent_qcloud_cos_rs::service::Service;
async {
let client = Client::new("foo", "bar", None, "qcloudtest-1256650966", "ap-guangzhou");
let resp = client.get_bucket_list().await;
assert!(resp.error_message.contains("403"));
};Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more