Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.03 KB

README.md

File metadata and controls

51 lines (35 loc) · 1.03 KB

Getting Started with Create React App

This project was bootstrapped with Create React App.

Base64 - Compressor Hit Here

HomePage.js

Hit to locate ImageToBase64 Here.

Code

// funcation

 const uploadImage = async (e) => {
    const file = e.target.files[0];
    const base64 = await base64Convertor(file);
    console.log(base64);
    setImage(base64);
  };

  const base64Convertor = (file) => {
    return new Promise((resolve, reject) => {
      const fileReader = new FileReader();
      fileReader.readAsDataURL(file);

      fileReader.onload = () => {
        resolve(fileReader.result);
      };

      fileReader.onerror = (error) => {
        reject(error);
      };
    });
  };

// return


<input
  type="file"
  accept="image/*"
  onChange={(e) => {
    uploadImage(e);
  }}
/>;