Paste Images into CodeMirror

I am currently using the beforeChange event to capture paste events into a CodeMirror pane and this works fine for text, but I am trying to paste in an image and then convert it into a base64 encoded data uri, which can be used as the user is writing Markdown.

If I try and drag an image into the CodeMirror pane, then I can’t see any property that allows me to check the Content-Type or contents - is this possible?

I can see the following properties being passed to the beforeChange event:

{"canceled":false,"from":{"line":0,"ch":0,"sticky":null,"xRel":1,"outside":1},"to":{"line":0,"ch":0,"sticky":null,"xRel":1,"outside":1},"text":[""],"origin":"paste"}

You’ll want to handle the "paste" event and directly look at the files in the event’s dataTransfer.

Thank you… I am not sure why I was using beforeChange for paste events, but I have it working now I have switched to paste instead.