Trying multipart
This commit is contained in:
parent
b0532b37ae
commit
00aed00bf6
6 changed files with 56 additions and 2 deletions
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -165,8 +165,10 @@ dependencies = [
|
|||
name = "dc09bin"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"ntex",
|
||||
"ntex-files",
|
||||
"ntex-multipart",
|
||||
"yarte",
|
||||
]
|
||||
|
||||
|
@ -738,6 +740,21 @@ dependencies = [
|
|||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntex-multipart"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9d196aea9ef18b3a0281406703e50df4af3602226626c081f28c9b95fb2d861"
|
||||
dependencies = [
|
||||
"derive_more",
|
||||
"futures",
|
||||
"httparse",
|
||||
"log",
|
||||
"mime",
|
||||
"ntex",
|
||||
"twoway",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntex-router"
|
||||
version = "0.5.3"
|
||||
|
@ -1416,12 +1433,28 @@ dependencies = [
|
|||
"tracing-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "twoway"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c57ffb460d7c24cd6eda43694110189030a3d1dfe418416d9468fd1c1d290b47"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"unchecked-index",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||
|
||||
[[package]]
|
||||
name = "unchecked-index"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c"
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.7.0"
|
||||
|
|
|
@ -6,8 +6,10 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.30"
|
||||
ntex = { version = "1.1.0", features = ["tokio"] }
|
||||
ntex-files = "0.4"
|
||||
ntex-multipart = "1.0.0"
|
||||
yarte = { version = "0.15.7", features = ["html-min"] }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
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")?
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
<div>
|
||||
File
|
||||
<textarea name="file-text"></textarea>
|
||||
<input type="file" name="file-bytes">
|
||||
</div>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
</header>
|
||||
<input type="radio" name="tab" class="htab" id="htab-file" aria-hidden="true" checked>
|
||||
<input type="radio" name="tab" class="htab" id="htab-link" aria-hidden="true">
|
||||
<form action="/api/upload" method="post" id="tab-file" role="tabpanel">
|
||||
<form action="/api/upload" method="post" enctype="multipart/form-data" id="tab-file" role="tabpanel">
|
||||
{{> no-auto-submit }}
|
||||
<div class="form-main">
|
||||
{{> file }}
|
||||
|
|
Loading…
Add table
Reference in a new issue