actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

use actix_multipart to get field name and value deserialized to struct

Open YounessBird opened this issue 3 years ago • 1 comments

I have looked through actix_multipart documentation, and I couldn't find if there is a method to get the field name and value to be deserialized to a struct

YounessBird avatar Feb 21 '22 13:02 YounessBird

I have use this

    let mut filename: Option<String> = None;
    // iterate over multipart stream
    while let Ok(Some(mut field)) = payload.try_next().await {
        let content_type = field.content_disposition();
        let name = content_type.get_filename().unwrap();
        filename = Some(name.to_string());
        // Field in turn is stream of *Bytes* object
        while let Some(chunk) = field.next().await {
            let data = chunk.unwrap();
            bytes.append(&mut data.to_vec());
        }
    }

modship avatar Mar 07 '22 09:03 modship