From 283d1d6134c805ac74fff7cc7e42ffb900113b5e Mon Sep 17 00:00:00 2001 From: serxoz Date: Thu, 20 Oct 2022 23:46:55 +0200 Subject: [PATCH] exemplo de uso --- README.md | 4 ++++ src/main.rs | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e65dfa0..7691b9c 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ Recibe un arquivo. Devolve un link para descargalo. ## Funcionamento +``` +curl -F'file=@fondo-mobil.jpg' http://localhost:3000/u + +``` ### Subida Cando recibe un arquivo: diff --git a/src/main.rs b/src/main.rs index 23bba04..a95f440 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,12 +37,13 @@ async fn root() -> &'static str { async fn upload(mut multipart: Multipart) { while let Some(field) = multipart.next_field().await.unwrap() { let name = field.name().unwrap().to_string(); + let filename = field.file_name().unwrap().to_string(); let data = field.bytes().await.unwrap(); println!("Length of `{}` is {} bytes", name, data.len()); // tracing::debug!("Length of `{}` is {} bytes", name, data.len()); - let mut file = File::create(name).await.expect("error creando arquivo"); + let mut file = File::create(filename).await.expect("error creando arquivo"); file.write_all(&data).await.expect("error gardando contido"); } }