diff --git a/Cargo.toml b/Cargo.toml index 67df3638..d12baab0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ members = [ "database_interactions/sqlx_todo", "forms/form", "forms/multipart", - "forms/multipart-async-std", "forms/multipart-s3", "graphql/graphql-demo", "graphql/juniper", diff --git a/forms/multipart-async-std/.gitignore b/forms/multipart-async-std/.gitignore deleted file mode 100644 index 8d2901e1..00000000 --- a/forms/multipart-async-std/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target -**/*.rs.bk -/tmp diff --git a/forms/multipart-async-std/Cargo.toml b/forms/multipart-async-std/Cargo.toml deleted file mode 100644 index 15cfdb1f..00000000 --- a/forms/multipart-async-std/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "multipart-async-std-example" -version = "0.3.0" -authors = ["Bevan Hunt "] -edition = "2018" -license = "MIT" -description = "Simple file uploader in Actix Web with Async/Await" -keywords = ["actix", "actix-web", "multipart"] -repository = "https://github.com/actix/examples" -readme = "README.md" - -[dependencies] -actix-web = "3" -actix-multipart = "0.3" -futures-util = "0.3" -async-std = "1.8" -sanitize-filename = "0.2" -uuid = { version = "0.8", features = ["v4"] } diff --git a/forms/multipart-async-std/LICENSE b/forms/multipart-async-std/LICENSE deleted file mode 100644 index 5a59c7c6..00000000 --- a/forms/multipart-async-std/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) [2019] [Bevan Hunt] - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/forms/multipart-async-std/README.md b/forms/multipart-async-std/README.md deleted file mode 100644 index 6ad89cf8..00000000 --- a/forms/multipart-async-std/README.md +++ /dev/null @@ -1,16 +0,0 @@ -# Actix Web File Upload with Async/Await - -### Run - -```bash -cd forms/multipart-async-std -cargo run -``` - -``` open web browser to localhost:3000 and upload file(s) ``` - -### Result - -``` file(s) will show up in ./tmp in the same directory as the running process ``` - -Note: this is a naive implementation and will panic on any error diff --git a/forms/multipart-async-std/src/main.rs b/forms/multipart-async-std/src/main.rs deleted file mode 100644 index 3fb4ad1d..00000000 --- a/forms/multipart-async-std/src/main.rs +++ /dev/null @@ -1,62 +0,0 @@ -use actix_multipart::Multipart; -use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer}; -use async_std::prelude::*; -use futures_util::TryStreamExt as _; -use uuid::Uuid; - -async fn save_file(mut payload: Multipart) -> Result { - // iterate over multipart stream - while let Ok(Some(mut field)) = payload.try_next().await { - let content_disposition = field - .content_disposition() - .ok_or_else(|| HttpResponse::BadRequest().finish())?; - - let filename = content_disposition.get_filename().map_or_else( - || Uuid::new_v4().to_string(), - |f| sanitize_filename::sanitize(f), - ); - - let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename)); - let mut f = async_std::fs::File::create(filepath).await?; - - // Field in turn is stream of *Bytes* object - while let Some(chunk) = field.try_next().await? { - f.write_all(&chunk).await?; - } - } - - Ok(HttpResponse::Ok().into()) -} - -fn index() -> HttpResponse { - let html = r#" - Upload Test - -
- - -
- - "#; - - HttpResponse::Ok() - .content_type("text/html; charset=utf-8") - .body(html) -} - -#[actix_web::main] -async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "info"); - async_std::fs::create_dir_all("./tmp").await?; - - HttpServer::new(|| { - App::new().wrap(middleware::Logger::default()).service( - web::resource("/") - .route(web::get().to(index)) - .route(web::post().to(save_file)), - ) - }) - .bind(("127.0.0.1", 8080))? - .run() - .await -}