murar8 / axum_typed_multipart

Type safe multipart/form-data handling for axum.
77 stars 13 forks source link

Limit Vec lengh in request body #75

Closed ChanManChan closed 4 weeks ago

ChanManChan commented 1 month ago
#[form_data(field_name = "pic", limit = "5MiB")]
pub pics: Vec<FieldData<NamedTempFile>>,

How do I limit the vec size here? I can't see the accepted form_data attributes. I want the vec size to be no more than 8.

murar8 commented 1 month ago

Hi @ChanManChan, I think having a length parameter would make sense and I'll see if I can squeeze the feature in. If you are in a pinch I guess setting the axum body limit to e.g. 1000MiB would limit the length to 1000/5 -> 200 elements. This of course would only be the maximum and the array could be smaller.

ChanManChan commented 1 month ago

Thanks @murar8. I'm currently using the axum body limit as a work around. But it is not an elegant solution. I'll be looking forward to your new version. Thanks again. This is a very helpful crate.

murar8 commented 4 weeks ago

@ChanManChan what do you think about using this crate? https://github.com/gengteng/axum-valid/tree/main?tab=readme-ov-file#-validatede-modifiede-validifiede-and-validifiedbyrefe The integration looks really nice and on second thought validation might be a bit out of scope for this crate.