Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.45k stars 319 forks source link

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

Open artknight opened 3 years ago

artknight commented 3 years ago

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

jxxe commented 2 years ago

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.