diff --git a/Cargo.lock b/Cargo.lock index 434fc74..50ef6d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -914,6 +914,24 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "multer" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01acbdc23469fd8fe07ab135923371d5f5a422fbf9c522158677c8eb15bc51c2" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http", + "httparse", + "log", + "memchr", + "mime", + "spin", + "version_check", +] + [[package]] name = "native-tls" version = "0.2.11" @@ -1319,6 +1337,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "syn" version = "1.0.109" @@ -1371,6 +1395,7 @@ dependencies = [ "actix-rt", "actix-web", "env_logger", + "multer", "reqwest", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index adf797b..6624faa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +multer = "2.1.0" actix = "0.13.0" actix-rt = "2.8.0" actix-web = "4.3.1" diff --git a/layouts/shortcodes/health-form.html b/layouts/shortcodes/health-form.html index b6f0b85..3758937 100644 --- a/layouts/shortcodes/health-form.html +++ b/layouts/shortcodes/health-form.html @@ -67,9 +67,9 @@ /* console.log(JSON.stringify(data)); */ fetch("http://localhost:4242/health-form", { method: "POST", - headers: { - "Content-Type": "multipart/form-data", - }, + /* headers: { + * "Content-Type": "multipart/form-data", + * }, */ body: data }).then((res) => { console.log(res); diff --git a/src/main.rs b/src/main.rs index 4267c98..67c3a5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::{env, io}; -use actix_web::{middleware, web, App, HttpServer, get, post, Responder, http::header::ContentType, HttpResponse, HttpRequest, http::{StatusCode, Method}}; +use actix_web::{middleware, web, App, HttpServer, get, post, Responder, http::header::ContentType, HttpResponse, HttpRequest, http::{StatusCode, Method}, HttpMessage}; +use multer::Multipart; #[actix_web::main] async fn main() -> io::Result<()> { @@ -21,5 +22,9 @@ async fn main() -> io::Result<()> { #[post("/health-form")] async fn form(req: HttpRequest) -> HttpResponse { println!("{req:?}"); + println!("{:?}", req.content_type()); + println!("{:?}", req); + println!("{:?}", req.headers().get("content-type")); + // let multipart = Multipart::new(stream, boundary); HttpResponse::Ok().respond_to(&req) }