OSS

Struct OSS 

Source
pub struct OSS { /* private fields */ }
Expand description

OSS配置

Implementations§

Source§

impl<'a> OSS

Source

pub fn from_env() -> Self

Source

pub fn open_debug(&self)

Source

pub fn new<S: Into<String>>( key_id: S, key_secret: S, endpoint: S, bucket: S, ) -> Self

Source

pub fn format_host<S: AsRef<str>>( &self, bucket: S, key: S, build: &RequestBuilder, ) -> String

Source

pub fn build_request<S: AsRef<str>>( &self, key: S, build: RequestBuilder, ) -> Result<(String, HeaderMap), InvalidHeaderValue>

Source

pub fn date(&self) -> String

Source§

impl OSS

Source

pub fn get_object<S: AsRef<str>>( &self, key: S, build: RequestBuilder, ) -> Result<Vec<u8>, OssError>

获取对象

§使用例子
use aliyun_oss_rust_sdk::oss::OSS;
use aliyun_oss_rust_sdk::request::RequestBuilder;
let oss = OSS::from_env();
let build = RequestBuilder::new();
let bytes = oss.get_object("/hello.txt", build).await.unwrap();
println!("file content: {}", String::from_utf8_lossy(bytes.as_slice()));
Source

pub fn get_upload_object_policy( &self, build: PolicyBuilder, ) -> Result<PolicyResp, OssError>

获取上传对象的policy

§使用例子
use aliyun_oss_rust_sdk::entity::PolicyBuilder;
use aliyun_oss_rust_sdk::oss::OSS;
let oss = OSS::from_env();
let policy_builder = PolicyBuilder::new()
            .with_expire(60 * 60)//1个小时过期
            .with_upload_dir("upload/mydir/")//上传目录
            .with_content_type("text/plain")//只允许上传文本.txt
           .with_max_upload_size(100 * 1024 * 1024);//只允许文件上传大小1G以内
let policy = oss.get_upload_object_policy(policy_builder).unwrap();
println!("policy: {:?}", policy);
//使用postman测试上传
//form-data的参数为OSSAccessKeyId、policy、signature、success_action_status、key、file
//key为上传的文件名包含路径、例如:upload/mydir/test.txt
//file为上传的文件,类型跟with_content_type一致
Source

pub fn put_object_from_file<S: AsRef<str>>( &self, key: S, file_path: S, build: RequestBuilder, ) -> Result<(), OssError>

上传文件(本地文件)

§使用例子
use aliyun_oss_rust_sdk::oss::OSS;
use aliyun_oss_rust_sdk::request::RequestBuilder;
let oss = OSS::from_env();
let builder = RequestBuilder::new()
    .with_expire(60);
let file_path = "./hello.txt";
oss.put_object_from_file("/hello.txt", file_path, builder).await.unwrap();
Source

pub fn pub_object_from_buffer<S: AsRef<str>>( &self, key: S, buffer: &[u8], build: RequestBuilder, ) -> Result<(), OssError>

上传文件(内存)

§使用例子
use aliyun_oss_rust_sdk::oss::OSS;
use aliyun_oss_rust_sdk::request::RequestBuilder;
let oss = OSS::from_env();
let builder = RequestBuilder::new()
    .with_expire(60);
let file_path = "./hello.txt";
let buffer = std::fs::read(file_path).unwrap();
oss.pub_object_from_buffer("/hello.txt", buffer.as_slice(), builder).await.unwrap();
Source

pub fn delete_object<S: AsRef<str>>( &self, key: S, build: RequestBuilder, ) -> Result<(), OssError>

删除文件

§使用例子
use aliyun_oss_rust_sdk::oss::OSS;
use aliyun_oss_rust_sdk::request::RequestBuilder;
let oss = OSS::from_env();
let builder = RequestBuilder::new()
   .with_expire(60);
oss.delete_object("/hello.txt", builder).await.unwrap();
Source

pub fn get_object_metadata<S: AsRef<str>>( &self, key: S, build: RequestBuilder, ) -> Result<ObjectMetadata, OssError>

获取对象元数据

§使用例子
use aliyun_oss_rust_sdk::oss::OSS;
use aliyun_oss_rust_sdk::request::RequestBuilder;
let oss = OSS::from_env();
let builder = RequestBuilder::new()
   .with_expire(60);
let metadata = oss.get_object_metadata("/hello.txt", builder).await.unwrap();
println!("{:?}", metadata);

Trait Implementations§

Source§

impl API for OSS

Source§

fn format_oss_resource_str<S: AsRef<str>>(&self, bucket: S, key: S) -> String

Source§

fn key_urlencode<S: AsRef<str>>(&self, key: S) -> String

Source§

fn format_key<S: AsRef<str>>(&self, key: S) -> String

Source§

impl<'a> AuthAPI for OSS

Source§

fn sign<S: AsRef<str>>(&self, key: S, build: &RequestBuilder) -> String

Source§

fn oss_sign<S: AsRef<str>>(&self, object: S, build: &RequestBuilder) -> String

Source§

impl Clone for OSS

Source§

fn clone(&self) -> OSS

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OSS

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl OSSInfo for OSS

Source§

impl UrlApi for OSS

Source§

fn sign_download_url<S: AsRef<str>>( &self, key: S, build: &RequestBuilder, ) -> String

获取签名下载URL Read more
Source§

fn sign_upload_url<S: AsRef<str>>( &self, key: S, build: &RequestBuilder, ) -> String

获取签名上传URL Read more
Source§

fn sign_url<S: AsRef<str>>(&self, key: S, build: &RequestBuilder) -> String

Source§

impl Send for OSS

Source§

impl Sync for OSS

Auto Trait Implementations§

§

impl Freeze for OSS

§

impl RefUnwindSafe for OSS

§

impl Unpin for OSS

§

impl UnwindSafe for OSS

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more