ohkami-rs/ohkami

How to upload files through multipart/form data

Closed this issue · 3 comments

How to upload files through multipart/form data

Thank you for opening issue! But I'm sorry, current ohkami can't handle multipart/form-data. Please wait for the development...

Thank you for opening issue! But I'm sorry, current ohkami can't handle multipart/form-data. Please wait for the development...

Ok, thank you

@kotlin2018

I'm very sorry that I've forgotten to respond for a long time...

Ohkami has already been able to handle multipart/form-data requests by builtin::payload::Multipart with Desrialize like

#[Payload(Multipart/D)]
struct FormData<'req> {
    #[serde(rename = "account-name")]
    account_name: Option<&'req str>,
    
    pics: Vec<File<'req>>,
}

async fn post_submit(form_data: FormData<'_>) -> NoContent {
    println!("\n\
        ===== submit =====\n\
        [account name] {:?}\n\
        [  pictures  ] {} files (mime: [{}])\n\
        ==================",
        form_data.account_name,
        form_data.pics.len(),
        form_data.pics.iter().map(|f| f.mimetype).collect::<Vec<_>>().join(", "),
    );

    NoContent
}

See examples/form/src/main.rs for full example!