Type Definition qiniu_http_client::AsyncPart
source · pub type AsyncPart<'a> = Part<AsyncPartBody<'a>>;
Available on crate feature
async
only.Expand description
异步 Multipart 表单组件
Implementations§
source§impl<'a> AsyncPart<'a>
impl<'a> AsyncPart<'a>
sourcepub fn stream(value: impl AsyncRead + Send + Unpin + 'a) -> Self
pub fn stream(value: impl AsyncRead + Send + Unpin + 'a) -> Self
设置异步 Multipart 的请求体为异步输入流
Examples found in repository?
src/client/request/multipart.rs (line 431)
420 421 422 423 424 425 426 427 428 429 430 431 432
pub async fn file_path<S: AsRef<OsStr> + ?Sized>(path: &S) -> IoResult<AsyncPart<'a>> {
let path = Path::new(path);
let file = File::open(&path).await?;
let mut metadata = PartMetadata::default().mime(mime_guess::from_path(path).first_or_octet_stream());
if let Some(file_name) = path.file_name() {
let file_name = match file_name.to_string_lossy() {
Cow::Borrowed(str) => FileName::from(str),
Cow::Owned(string) => FileName::from(string),
};
metadata = metadata.file_name(file_name);
}
Ok(AsyncPart::stream(file).metadata(metadata))
}