actix / actix/actix-web

Is it possible to split multipart by fields?

Offen
#1,478 0 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
A-multipart C-improvement
Vorherrschende Sprache
Rust
Sterne
24.8k
Forks
1.9k
Ø Merge
23 Std. 10 Min.
Gemergte PRs (30 T.)
26

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.