Trying multipart

This commit is contained in:
DarkCat09 2024-03-09 20:13:36 +04:00
parent b0532b37ae
commit 00aed00bf6
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
6 changed files with 56 additions and 2 deletions

16
src/api.rs Normal file
View file

@ -0,0 +1,16 @@
use futures::{StreamExt, TryStreamExt};
use ntex::web::{self, Error, HttpResponse};
use ntex_multipart::Multipart;
#[web::post("/api/upload")]
async fn upload(mut payload: Multipart) -> Result<HttpResponse, Error> {
while let Ok(Some(mut field)) = payload.try_next().await {
println!("CT: {:?}", field.content_type());
println!("H: {:?}", field.headers());
while let Some(chunk) = field.next().await {
println!("-- CHUNK: \n{:?}", std::str::from_utf8(&chunk?));
}
}
Ok(HttpResponse::Ok().into())
}

View file

@ -1,6 +1,7 @@
use ntex::web::{self, App};
use ntex_files;
mod api;
mod pages;
#[ntex::main]
@ -8,6 +9,7 @@ async fn main() -> std::io::Result<()> {
web::server(move || {
App::new()
.service(pages::index)
.service(api::upload)
.service(ntex_files::Files::new("/static", "./static"))
})
.bind("127.0.0.1:3002")?