add zip file support

This commit is contained in:
2020-04-04 01:38:54 +08:00
parent 13fff9569b
commit 831d66fddb
5 changed files with 31 additions and 34 deletions

View File

@@ -22,18 +22,18 @@ pub const OSS_VERB_PUT: &str = "PUT";
pub const OSS_VERB_DELETE: &str = "DELETE";
// https://help.aliyun.com/document_detail/31952.html
pub struct OSSClient<'a> {
pub endpoint: &'a str,
pub access_key_id: &'a str,
pub access_key_secret: &'a str,
pub struct OSSClient {
pub endpoint: String,
pub access_key_id: String,
pub access_key_secret: String,
}
impl<'a> OSSClient<'a> {
pub fn new(endpoint: &'a str, access_key_id: &'a str, access_key_secret: &'a str) -> OSSClient<'a> {
impl OSSClient {
pub fn new(endpoint: &str, access_key_id: &str, access_key_secret: &str) -> OSSClient {
OSSClient {
endpoint: endpoint,
access_key_id: access_key_id,
access_key_secret: access_key_secret,
endpoint: endpoint.to_owned(),
access_key_id: access_key_id.to_owned(),
access_key_secret: access_key_secret.to_owned(),
}
}
@@ -78,9 +78,9 @@ impl<'a> OSSClient<'a> {
pub fn generate_signed_url(&self, verb: &str, bucket_name: &str, key: &str, expire_in_seconds: u64, is_https: bool) -> String {
let mut signed_url = String::with_capacity(1024);
signed_url.push_str(if is_https { "https://" } else { "http://" });
signed_url.push_str(iff!(is_https, "https://", "http://"));
let endpoint = &remove_endpoint_http_or_s(self.endpoint);
let endpoint = &remove_endpoint_http_or_s(&self.endpoint);
signed_url.push_str(&format!("{}.{}/{}", bucket_name, endpoint, key));
let current_secs = get_current_secs();
@@ -89,7 +89,7 @@ impl<'a> OSSClient<'a> {
signed_url.push_str("?Expires=");
signed_url.push_str(expire_secs.to_string().as_str());
signed_url.push_str("&OSSAccessKeyId=");
signed_url.push_str(&urlencoding::encode(self.access_key_id));
signed_url.push_str(&urlencoding::encode(&self.access_key_id));
signed_url.push_str("&Signature=");
let to_be_signed = get_to_be_signed(verb, expire_secs, bucket_name, key);