remove rust main
This commit is contained in:
parent
350e7d4b33
commit
7b9f13ef74
88
src/main.rs
88
src/main.rs
|
@ -1,88 +0,0 @@
|
|||
use actix_multipart::{
|
||||
form::{
|
||||
tempfile::{TempFile, TempFileConfig},
|
||||
text::Text,
|
||||
MultipartForm,
|
||||
},
|
||||
Multipart,
|
||||
};
|
||||
use actix_web::{middleware, post, web, App, Error, HttpResponse, HttpServer, Result};
|
||||
// use serde::Deserialize;
|
||||
use futures_util::StreamExt as _;
|
||||
use std::{env, io};
|
||||
|
||||
#[derive(Debug, MultipartForm)]
|
||||
struct HealthForm {
|
||||
#[multipart(rename = "file")]
|
||||
files: Vec<TempFile>,
|
||||
firstname: Text<String>,
|
||||
lastname: Text<String>,
|
||||
birthdate: Text<String>,
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "actix_web=debug,actix_server=info");
|
||||
env_logger::init();
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
// enable logger - always register actix-web Logger middleware last
|
||||
.wrap(middleware::Logger::default())
|
||||
.app_data(web::FormConfig::default().limit(1048576))
|
||||
// register HTTP requests handlers
|
||||
.service(form)
|
||||
})
|
||||
.bind("0.0.0.0:4242")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
// #[post("/health-form")]
|
||||
// async fn form(mut form: Multipart) -> Result<HttpResponse, Error> {
|
||||
// // println!("{form:?}");
|
||||
// while let Some(item) = form.next().await {
|
||||
// let mut field = item?;
|
||||
// // let mut value = "";
|
||||
// let name = field.name();
|
||||
// let content_type = field.content_type().unwrap().to_string();
|
||||
// if content_type == "application/octet-stream" {
|
||||
// // Handle file field
|
||||
// // You can save the file or process its contents here
|
||||
// while let Some(chunk) = field.next().await {
|
||||
// // Process file chunk
|
||||
// println!("chunk: {:?}", std::str::from_utf8(&chunk?));
|
||||
// }
|
||||
// } else {
|
||||
// // Handle other field types (e.g., text fields)
|
||||
// let field_value = field
|
||||
// .next()
|
||||
// .await
|
||||
// .expect("Field value not found")
|
||||
// .expect("Field value not found");
|
||||
|
||||
// // Process the field value (e.g., store in a database, perform validation, etc.)
|
||||
// println!("Field {:?}: {:?}", name, field_value);
|
||||
// }
|
||||
// // while let Some(chunk) = field.try_next().await {
|
||||
// // let value = std::str::from_utf8(&chunk?).unwrap();
|
||||
// // println!("{:?}: {:?}", name, value);
|
||||
// // }
|
||||
// }
|
||||
// Ok(HttpResponse::Ok().into())
|
||||
// }
|
||||
|
||||
#[post("/health-form")]
|
||||
async fn form(form: MultipartForm<HealthForm>) -> Result<HttpResponse, Error> {
|
||||
println!("{:?}", form.firstname);
|
||||
println!("{:?}", form.lastname);
|
||||
Ok(HttpResponse::Ok().into())
|
||||
}
|
||||
|
||||
fn get_boundary(s: &str) -> &str {
|
||||
if let Some(index) = s.find("=") {
|
||||
&s[(index + 1)..]
|
||||
} else {
|
||||
s
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue