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"
|
name = "dc09bin"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"futures",
|
||||||
"ntex",
|
"ntex",
|
||||||
"ntex-files",
|
"ntex-files",
|
||||||
|
"ntex-multipart",
|
||||||
"yarte",
|
"yarte",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -738,6 +740,21 @@ dependencies = [
|
||||||
"syn 1.0.109",
|
"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]]
|
[[package]]
|
||||||
name = "ntex-router"
|
name = "ntex-router"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
|
@ -1416,12 +1433,28 @@ dependencies = [
|
||||||
"tracing-log",
|
"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]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.17.0"
|
version = "1.17.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unchecked-index"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eeba86d422ce181a719445e51872fa30f1f7413b62becb52e95ec91aa262d85c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicase"
|
name = "unicase"
|
||||||
version = "2.7.0"
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
futures = "0.3.30"
|
||||||
ntex = { version = "1.1.0", features = ["tokio"] }
|
ntex = { version = "1.1.0", features = ["tokio"] }
|
||||||
ntex-files = "0.4"
|
ntex-files = "0.4"
|
||||||
|
ntex-multipart = "1.0.0"
|
||||||
yarte = { version = "0.15.7", features = ["html-min"] }
|
yarte = { version = "0.15.7", features = ["html-min"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[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::web::{self, App};
|
||||||
use ntex_files;
|
use ntex_files;
|
||||||
|
|
||||||
|
mod api;
|
||||||
mod pages;
|
mod pages;
|
||||||
|
|
||||||
#[ntex::main]
|
#[ntex::main]
|
||||||
|
@ -8,6 +9,7 @@ async fn main() -> std::io::Result<()> {
|
||||||
web::server(move || {
|
web::server(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.service(pages::index)
|
.service(pages::index)
|
||||||
|
.service(api::upload)
|
||||||
.service(ntex_files::Files::new("/static", "./static"))
|
.service(ntex_files::Files::new("/static", "./static"))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:3002")?
|
.bind("127.0.0.1:3002")?
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<div>
|
<div>
|
||||||
File
|
<textarea name="file-text"></textarea>
|
||||||
|
<input type="file" name="file-bytes">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
</header>
|
</header>
|
||||||
<input type="radio" name="tab" class="htab" id="htab-file" aria-hidden="true" checked>
|
<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">
|
<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 }}
|
{{> no-auto-submit }}
|
||||||
<div class="form-main">
|
<div class="form-main">
|
||||||
{{> file }}
|
{{> file }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue