exemplo de uso

This commit is contained in:
serxoz 2022-10-20 23:46:55 +02:00
parent 101e0b6566
commit 283d1d6134
2 changed files with 6 additions and 1 deletions

View File

@ -5,6 +5,10 @@ Recibe un arquivo.
Devolve un link para descargalo. Devolve un link para descargalo.
## Funcionamento ## Funcionamento
```
curl -F'file=@fondo-mobil.jpg' http://localhost:3000/u
```
### Subida ### Subida
Cando recibe un arquivo: Cando recibe un arquivo:

View File

@ -37,12 +37,13 @@ async fn root() -> &'static str {
async fn upload(mut multipart: Multipart) { async fn upload(mut multipart: Multipart) {
while let Some(field) = multipart.next_field().await.unwrap() { while let Some(field) = multipart.next_field().await.unwrap() {
let name = field.name().unwrap().to_string(); let name = field.name().unwrap().to_string();
let filename = field.file_name().unwrap().to_string();
let data = field.bytes().await.unwrap(); let data = field.bytes().await.unwrap();
println!("Length of `{}` is {} bytes", name, data.len()); println!("Length of `{}` is {} bytes", name, data.len());
// tracing::debug!("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"); file.write_all(&data).await.expect("error gardando contido");
} }
} }