Skip to content

How to encode file string from FileEngine to into a base64 image #3259

Answered by onweru
onweru asked this question in Q&A
Discussion options

You must be logged in to vote

I got it to work by:

  1. Using read_file instead of read_file_to_string method
  2. Running (1) output through base64 crate
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)
        );

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by onweru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant