easy-markdown-editor icon indicating copy to clipboard operation
easy-markdown-editor copied to clipboard

Is there an example on how to use `imageUploadFunction`?

Open artknight opened this issue 4 years ago • 1 comments

It would be great to see some code on how the imageUploadFunction method is supposed to be used! The docs are very slim on that!

Art

artknight avatar May 26 '21 15:05 artknight

In case anyone is finding this through Google, here's an example:

new EasyMDE({
    imageUploadFunction: (file, onSuccess, onError) => {
        const reader = new FileReader();
        reader.onload = () => onSuccess(reader.result);
        reader.onerror = () => onError(`Error loading ${file.name}`);
        reader.readAsDataURL(file);
    }
})

I wouldn't recommend storing the images as data URIs in your markdown document, this is just a simple example. The file variable is a File object: https://developer.mozilla.org/en-US/docs/Web/API/File.

jxxe avatar May 24 '22 05:05 jxxe