actix / actix/actix-web

Is it possible to split multipart by fields?

Abierto
#1,478 0 comentarios 3 reacciones 0 asignados Ver en GitHub
A-multipart C-improvement
Lenguaje dominante
Rust
Estrellas
24.8k
Forks
1.9k
Merge medio
23 h 10 min
PR fusionados (30 d)
26

Descripción

Hi, is there a way to split a Multipart payload into different (potentially serde-deserializable) Fields?

For example, if my request expects a multipart with a single file + a list of strings.

In python `fastapi` you can do something like:
```python
from fastapi import File, Form, UploadFile
async def my_request(
request: Request,
my_file: UploadFile = File(...),
another_form: List[str] = Form(...)
):
# do the thing
```
some docs here https://fastapi.tiangolo.com/tutorial/request-files/#file-parameters-with-uploadfile

Currently in all actix examples it's always just a Multipart payload that gets iterated, and then you have to match the fields based on the name in the content_type / disposition thing. If the name matching was inferred from the request signature (and potentially the stream deserialized into appropriate objects), this would be very convenient, I feel.

Mock example that I would ideally wish to use would go something like
```rust
#[derive(Deserialize)]
struct Another {
uuid: Uuid,
name: String
}

pub async fn my_endpoint(
my_file: Field, // This would be the field that represents a stream of bytes. Maybe not Field?
others: web::Json>) -> impl Responder {
"mock"
}
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.