Trait Files

Source
pub trait Files<Path>: AlignBuilder + GetStdWithPath<Path>
where Path: Send + Sync + 'static,
{ const DEFAULT_CONTENT_TYPE: &'static str = DEFAULT_CONTENT_TYPE; // Provided methods fn put_file<'life0, 'async_trait, P>( &'life0 self, file_name: P, path: Path, ) -> Pin<Box<dyn Future<Output = Result<String, FileError>> + Send + 'async_trait>> where P: 'async_trait + Into<PathBuf> + AsRef<Path> + Send + Sync, Self: Sync + 'async_trait, 'life0: 'async_trait { ... } fn put_content<'life0, 'async_trait, F>( &'life0 self, content: Vec<u8>, path: Path, get_content_type: F, ) -> Pin<Box<dyn Future<Output = Result<String, FileError>> + Send + 'async_trait>> where F: Fn(&Vec<u8>) -> Option<&'static str> + Send + Sync + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait { ... } fn put_content_base<'life0, 'life1, 'async_trait>( &'life0 self, content: Vec<u8>, content_type: &'life1 str, path: Path, ) -> Pin<Box<dyn Future<Output = Result<Response, FileError>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn get_object<'life0, 'async_trait, Num, R>( &'life0 self, path: Path, range: R, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, FileError>> + Send + 'async_trait>> where R: Into<ContentRange<Num>> + Send + Sync + 'async_trait, ContentRange<Num>: Into<HeaderValue>, Num: 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait { ... } fn delete_object<'life0, 'async_trait>( &'life0 self, path: Path, ) -> Pin<Box<dyn Future<Output = Result<(), FileError>> + Send + 'async_trait>> where Self: Sync + 'async_trait, 'life0: 'async_trait { ... } }
Expand description

§文件集合的相关操作

在对文件执行相关操作的时候,需要指定文件路径

包括 上传,下载,删除等功能 在 ClientBucket, ObjectList 等结构体中均已实现,其中 Client 是在默认的 bucket 上操作文件, 而 Bucket, ObjectList 则是在当前的 bucket 上操作文件

Provided Associated Constants§

Source

const DEFAULT_CONTENT_TYPE: &'static str = DEFAULT_CONTENT_TYPE

§默认的文件类型

在上传文件时,如果找不到合适的 mime 类型,可以使用

Provided Methods§

Source

fn put_file<'life0, 'async_trait, P>( &'life0 self, file_name: P, path: Path, ) -> Pin<Box<dyn Future<Output = Result<String, FileError>> + Send + 'async_trait>>
where P: 'async_trait + Into<PathBuf> + AsRef<Path> + Send + Sync, Self: Sync + 'async_trait, 'life0: 'async_trait,

§上传文件到 OSS

需指定文件的路径

如果获取不到文件类型,则使用默认的文件类型,如果您不希望这么做,可以使用 put_content_base 方法

Source

fn put_content<'life0, 'async_trait, F>( &'life0 self, content: Vec<u8>, path: Path, get_content_type: F, ) -> Pin<Box<dyn Future<Output = Result<String, FileError>> + Send + 'async_trait>>
where F: Fn(&Vec<u8>) -> Option<&'static str> + Send + Sync + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait,

§上传文件内容到 OSS

需指定要上传的文件内容 以及根据文件内容获取文件类型的闭包

如果获取不到文件类型,则使用默认的文件类型,如果您不希望这么做,可以使用 put_content_base 方法

§Examples

上传 tauri 升级用的签名文件

use infer::Infer;
use aliyun_oss_client::file::Files;

fn sig_match(buf: &[u8]) -> bool {
    return buf.len() >= 3 && buf[0] == 0x64 && buf[1] == 0x57 && buf[2] == 0x35;
}
let mut infer = Infer::new();
infer.add("application/pgp-signature", "sig", sig_match);

let get_content_type = |content: &Vec<u8>| match infer.get(content) {
    Some(con) => Some(con.mime_type()),
    None => None,
};
let content: Vec<u8> = String::from("dW50cnVzdGVkIGNvbW1lbnQ6IHNpxxxxxxxxx").into_bytes();
let res = client
    .put_content(content, "xxxxxx.msi.zip.sig", get_content_type)
    .await;
assert!(res.is_ok());
Source

fn put_content_base<'life0, 'life1, 'async_trait>( &'life0 self, content: Vec<u8>, content_type: &'life1 str, path: Path, ) -> Pin<Box<dyn Future<Output = Result<Response, FileError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

最核心的上传文件到 OSS 的方法

Source

fn get_object<'life0, 'async_trait, Num, R>( &'life0 self, path: Path, range: R, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, FileError>> + Send + 'async_trait>>
where R: Into<ContentRange<Num>> + Send + Sync + 'async_trait, ContentRange<Num>: Into<HeaderValue>, Num: 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait,

§获取 OSS 上文件的部分或全部内容
Source

fn delete_object<'life0, 'async_trait>( &'life0 self, path: Path, ) -> Pin<Box<dyn Future<Output = Result<(), FileError>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

§删除 OSS 上的文件

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<P: Send + Sync + 'static, T: AlignBuilder + GetStdWithPath<P>> Files<P> for T

§为更多的类型实现 上传,下载,删除等功能

ClientBucket, ObjectList 等结构体中均已实现,其中 Client 是在默认的 bucket 上操作文件, 而 Bucket, ObjectList 则是在当前的 bucket 上操作文件