mirror of
https://github.com/chatmail/core.git
synced 2026-05-04 13:56:30 +03:00
Initial draft for HTTP file upload.
This commit is contained in:
17
src/upload.rs
Normal file
17
src/upload.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use crate::context::Context;
|
||||
use crate::error::{bail, Result};
|
||||
use async_std::path::PathBuf;
|
||||
|
||||
/// Upload file to a HTTP upload endpoint.
|
||||
pub async fn upload_file(_context: &Context, endpoint: String, file: PathBuf) -> Result<String> {
|
||||
// TODO: Use tokens for upload, encrypt file with PGP.
|
||||
let response = surf::post(endpoint).body_file(file)?.await;
|
||||
if let Err(err) = response {
|
||||
bail!("Upload failed: {}", err);
|
||||
}
|
||||
let mut response = response.unwrap();
|
||||
match response.body_string().await {
|
||||
Ok(string) => Ok(string),
|
||||
Err(err) => bail!("Invalid response from upload: {}", err),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user