-
Problem Steps To Reproduce
use web_sys::{js_sys::Uint8Array, Blob, BlobPropertyBag};
use yew::prelude::*;
#[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());
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>
}
}
Expected behavior Environment:
Minimal Example Code to reproduce: yew-blob-download-bug.zip I also tried different methods to Encode and Blob creation but without success. |
Beta Was this translation helpful? Give feedback.
Answered by
ranile
Mar 4, 2024
Replies: 1 comment 3 replies
-
This happens because you convert the string into bytes before creating the blob. The blob is created with the string of bytes (UInt8Array). You want to create a blob with a string |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Chtau
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This happens because you convert the string into bytes before creating the blob. The blob is created with the string of bytes (UInt8Array). You want to create a blob with a string