add openpgp, dep oss rust

This commit is contained in:
2019-11-29 01:09:54 +08:00
parent 730b3b7728
commit 6891d4daf1
4 changed files with 191 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
use std::{
fs::File,
time::SystemTime,
};
use crypto::{
@@ -9,6 +10,8 @@ use crypto::{
hmac::Hmac,
sha1::Sha1,
};
use rust_util::XResult;
use reqwest::Response;
pub const OSS_VERB_GET: &str = "GET";
pub const OSS_VERB_PUT: &str = "PUT";
@@ -29,6 +32,11 @@ impl<'a> OSSClient<'a> {
}
}
pub fn put_file(&self, bucket_name: &str, key: &str, expire_in_seconds: u64, file: File) -> XResult<Response> {
let client = reqwest::Client::new();
Ok(client.put(&self.generate_signed_put_url(bucket_name, key, expire_in_seconds)).body(file).send()?)
}
pub fn generate_signed_put_url(&self, bucket_name: &str, key: &str, expire_in_seconds: u64) -> String {
self.generate_signed_url(OSS_VERB_PUT, bucket_name, key, expire_in_seconds, true)
}