actix / actix/actix-web

Is it possible to split multipart by fields?

Aperta
#1,478 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub
A-multipart C-improvement
Lingua principale
Rust
Stelle
24.8k
Fork
1.9k
Merge medio
23h 10m
PR unite (30g)
26

Descrizione

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"
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.