-
I have the following code. pub async fn upload_image(evt: Event<FormData>) {
if let Some(file_engine) = evt.files() {
let files = file_engine.files();
for file_name in &files {
if let Some(file) = file_engine.read_file_to_string(file_name).await {
let avatar = base64_url::encode(&file); Expected output
Actual output
I can't figure out how to get to the desired outcome that:
|
Beta Was this translation helpful? Give feedback.
Answered by
onweru
Jan 8, 2025
Replies: 1 comment
-
I got it to work by: pub async fn upload_image(evt: Event<FormData>) {
if let Some(file_engine) = evt.files() {
let files = file_engine.files();
for file_name in &files {
let file_type = get_file_type(file_name); // check files mime type e.g jpeg
if let Some(file) = file_engine.read_file(file_name).await {
let file = format!(
"data:image/{};base64,{}",
file_type,
BASE64_STANDARD.encode(&file)
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
onweru
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got it to work by:
read_file
instead ofread_file_to_string
method