-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
In the docs for FileStreams (to upload a file) we see the next example:
// Our client component calls the endpoint with `file.into()`
fn app() -> Element {
rsx! {
h3 { "Upload as FileUpload" }
div {
ondragover: move |evt| evt.prevent_default(),
ondrop: move |evt| async move {
evt.prevent_default();
for file in files {
_ = upload_file_as_filestream(file.into()).await;
}
},
"Drop files here"
}
}
}
// Our server endpoint accepts `FileStream`
#[post("/api/upload_as_file_stream")]
async fn upload_file_as_filestream(mut upload: FileStream) -> Result<()> {
// ...
}First the loop file in files is using an undeclared variable, in reality it has to come from evt.files().
Second the method .files() is available only if we import the proper trait use dioxus_html::HasFileData;.
Final code would be like this:
// import this to allow evt.files()
use dioxus_html::HasFileData;
// Our client component calls the endpoint with `file.into()`
fn app() -> Element {
rsx! {
h3 { "Upload as FileUpload" }
div {
ondragover: move |evt| evt.prevent_default(),
ondrop: move |evt| async move {
evt.prevent_default();
for file in evt.files() {
_ = upload_file_as_filestream(file.into()).await;
}
},
"Drop files here"
}
}
}Metadata
Metadata
Assignees
Labels
No labels