pub trait Files<Path>: AlignBuilder + GetStdWithPath<Path> {
const DEFAULT_CONTENT_TYPE: &'static str = super::DEFAULT_CONTENT_TYPE;
// Provided methods
fn put_file<P: Into<PathBuf> + AsRef<Path>>(
&self,
file_name: P,
path: Path,
) -> Result<String, FileError> { ... }
fn put_content<F>(
&self,
content: Vec<u8>,
path: Path,
get_content_type: F,
) -> Result<String, FileError>
where F: Fn(&Vec<u8>) -> Option<&'static str> { ... }
fn put_content_base(
&self,
content: Vec<u8>,
content_type: &str,
path: Path,
) -> Result<Response, FileError> { ... }
fn get_object<Num, R>(
&self,
path: Path,
range: R,
) -> Result<Vec<u8>, FileError>
where R: Into<ContentRange<Num>>,
ContentRange<Num>: Into<HeaderValue> { ... }
fn delete_object(&self, path: Path) -> Result<(), FileError> { ... }
}
Expand description
§文件集合的相关操作
在对文件执行相关操作的时候,需要指定文件路径
Provided Associated Constants§
Sourceconst DEFAULT_CONTENT_TYPE: &'static str = super::DEFAULT_CONTENT_TYPE
const DEFAULT_CONTENT_TYPE: &'static str = super::DEFAULT_CONTENT_TYPE
§默认的文件类型
在上传文件时,如果找不到合适的 mime 类型,可以使用
Provided Methods§
Sourcefn put_file<P: Into<PathBuf> + AsRef<Path>>(
&self,
file_name: P,
path: Path,
) -> Result<String, FileError>
fn put_file<P: Into<PathBuf> + AsRef<Path>>( &self, file_name: P, path: Path, ) -> Result<String, FileError>
§上传文件到 OSS
需指定文件的路径
Sourcefn put_content<F>(
&self,
content: Vec<u8>,
path: Path,
get_content_type: F,
) -> Result<String, FileError>
fn put_content<F>( &self, content: Vec<u8>, path: Path, get_content_type: F, ) -> Result<String, FileError>
§上传文件内容到 OSS
需指定要上传的文件内容 以及根据文件内容获取文件类型的闭包
§Examples
上传 tauri 升级用的签名文件
use infer::Infer;
use crate::aliyun_oss_client::file::BlockingFiles;
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);
assert!(res.is_ok());
Sourcefn put_content_base(
&self,
content: Vec<u8>,
content_type: &str,
path: Path,
) -> Result<Response, FileError>
fn put_content_base( &self, content: Vec<u8>, content_type: &str, path: Path, ) -> Result<Response, FileError>
最原始的上传文件的方法
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.