exemplo de uso
This commit is contained in:
parent
101e0b6566
commit
283d1d6134
@ -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:
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user