pub fn DownloadBlob(props: &DownloadBlobProps) -> Html {
let array_buffer = props.text.clone().into_bytes();
let uint8_array = Uint8Array::from(array_buffer.as_slice());
let blob = Blob::new_with_u8_array_sequence_and_options(
&uint8_array,
BlobPropertyBag::new().type_("text/plain"),
)
.expect("Failed to create Blob");
let url = web_sys::Url::create_object_url_with_blob(&blob)
.expect("Failed to create object URL from Blob");
html! {
<a
href={url}
download="file.txt"
>
{ "Download File" }
</a>
}
}
4. Download the file provided by the `Url`
5. The Provided String Value "Test" is shown as "84101115116" in the File
**Expected behavior**
The File should have the provided String value as Content.
**Environment:**
- Yew version: v0.21, master
- Rust version: 1.75.0
- Build tool, if relevant: trunk
- OS: Windows 10
- Browser and version: Brave 1.63.165 Chromium 122.0.6261.94, Firefox 123.0, Edge 122.0.2.2365.66
Minimal Example Code to reproduce: [yew-blob-download-bug.zip](https://github.com/yewstack/yew/files/14483807/yew-blob-download-bug.zip)
I also tried different methods to Encode and Blob creation but without success.
Problem If a Blob is created the bytes their encoding is wrong.
Steps To Reproduce
Blob
with aString
("Test") as contentUrl
from theBlob
[derive(PartialEq, Properties)]
pub struct DownloadBlobProps { pub text: String, }
[function_component]
pub fn DownloadBlob(props: &DownloadBlobProps) -> Html { let array_buffer = props.text.clone().into_bytes(); let uint8_array = Uint8Array::from(array_buffer.as_slice());
}