diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file_upload.rs | 11 | ||||
-rw-r--r-- | src/main.rs | 2 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/file_upload.rs b/src/file_upload.rs index f72ab8b..c0ec95f 100644 --- a/src/file_upload.rs +++ b/src/file_upload.rs @@ -9,7 +9,8 @@ use std::{ path::{Component, PathBuf}, }; -pub fn save_file( +/// Create future to save file. +fn save_file( field: multipart::Field<dev::Payload>, file_path: PathBuf, ) -> Box<Future<Item = i64, Error = Error>> { @@ -30,7 +31,8 @@ pub fn save_file( ) } -pub fn handle_multipart( +/// Create new future to handle file as multipart data. +fn handle_multipart( item: multipart::MultipartItem<dev::Payload>, mut file_path: PathBuf, ) -> Box<Stream<Item = i64, Error = Error>> { @@ -65,6 +67,11 @@ pub fn handle_multipart( } } +/// Handle incoming request to upload file. +/// Target file path is expected as path parameter in URI and is interpreted as relative from +/// server root directory. Any path which will go outside of this directory is considered +/// invalid. +/// This method returns future. pub fn upload_file(req: &HttpRequest<crate::MiniserveConfig>) -> FutureResponse<HttpResponse> { if !req.query().contains_key("path") { return Box::new(future::ok( diff --git a/src/main.rs b/src/main.rs index 37a3226..fb7e321 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,7 +197,7 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> { let random_route = app.state().random_route.clone().unwrap_or_default(); let full_route = format!("/{}", random_route); - //allow file upload + // Allow file upload let app = app.resource("/upload", |r| { r.method(Method::POST).f(file_upload::upload_file) }); |