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"); } }