0

I am trying to generate a base64 string of local URL of image. I searched a lot for that but didn't got any answer. I found many example to convert a base64 string with a HTTP URL of image but I have local URL of image. I tried it with create a file object but its not working. Here is a example what I tried:

convertFileToDataURLviaFileReader(url){
    var file = new File([""],url, {type: "image/jpeg"});
    let reader = new FileReader();
    reader.onload = (event) => {
        var base64 = event.target.result;
        return base64;
    };
    reader.readAsDataURL(file);     
}

Here URL is a absolute path of image : file:\\C:\Users\abc\Pictures\butterfly.jpg This example is not generating a base64 image completely ie only returning a blank string :

Output

data:/
Gitesh Purbia
  • 1,094
  • 1
  • 12
  • 26

0 Answers0