DioxusLabs / DioxusLabs/dioxus
Doc for file streams is incomplete
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
In the [docs for FileStreams](https://dioxuslabs.com/learn/0.7/essentials/fullstack/streams#file-streams) (to upload a file) we see the next example:
```rust
// 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:
```rust
// 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"
}
}
}
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.