2

I'm making a paste image from clipboard function then I need to convert blob data to base64 encoded data url, here's the code:

function handlepaste (event, e) { 
    var items = e.clipboardData.items;
    event.innerHTML = items[0].getAsFile();
    FileReader.readAsDataURL( event.innerHTML );

   if (event.childNodes && event.childNodes.length > 0) {
   $('body').append( event.innerHTML );
   }
    if (e.preventDefault) {
            e.stopPropagation();
            e.preventDefault();
    }
    return false;
}

but the code's not working for me, Chrome console log says:

Uncaught TypeError: Object function FileReader() { [native code] } has no method 'readAsDataURL'

How can I turn [object Blob] to data:image/png;base64,iVBORw...?

1

1 Answer 1

3

I think you haven't instantiated FileReader properly: var file_reader = new FileReader();

And then use file_reader.readAsDataURL(...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.