I have a form with a file input (filename
):
use yew::prelude::*;
html! {
<form enctype={ "multipart/form-data" } onsubmit={ form_onsubmit }>
<input type="file" name="filename">
<button type="submit">Submit</button>
</form>
}
I am able to get the web_sys::FormData
with this function:
use wasm_bindgen::JsCast;
use web_sys::{EventTarget, HtmlFormElement, FormData};
use gloo_console::debug;
let form_onsubmit = {
Callback::from(move |event: SubmitEvent| {
let target: Option<EventTarget> = event.target();
debug!(target.clone());
let form = target.and_then(|t| t.dyn_into::<HtmlFormElement>().ok());
debug!(form.clone());
if let Some(form) = form {
let form_data = FormData::new_with_form(&form).expect("Expecting form data");
debug!(form_data);
//let form = reqwest::multipart::Form::new()
// .part(form_data.get("filename"))
};
event.prevent_default();
})
};
Is there a way to convert the content of the web_sys::FormData
to reqwest::multipart::Form
?