Trying multipart
This commit is contained in:
parent
b0532b37ae
commit
00aed00bf6
6 changed files with 56 additions and 2 deletions
16
src/api.rs
Normal file
16
src/api.rs
Normal 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())
|
||||
}
|
|
@ -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")?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue