Monday, 24 April 2017

Passing Node FileStream Image to HTML5 FileReader API

How can I use Node FileSystem to open a file but have it processed to the FileReader API?

const myFile = "C:\Users\Me\Image.png";

fs.readFile(myFile, (error, data) => {
    const blob = new Blob(data);

    const fileReader = new FileReader();
    fileReader.readAsDataURL(blob);

    fileReader.addEventListener("load", () => {
        const image = new Image();
        image.src = fileReader.result;

        document.body.appendChild(image);
    });
});

This code doesn't throw an errors, but it doesn't work.



via TheDarkIn1978

No comments:

Post a Comment