DEV Community

Discussion on: What's a good light weight library to handle inputting text that also supports file uploads?

Collapse
 
nektro profile image
Meghan (she/her)

This isn't fully tested but should be pretty close :)
(Filler variables are in caps)

INPUT_ELEMENT.addEventListener("paste", async (e) => {
    const f = e.clipboardData.items[0];
    const d = new FormData();
    d.append("picture", f);
    return fetch(IMAGE_HOST, {
        method: "POST",
        body: d
    })
    .then((x) => x.text())
    .then((x) => {
        INPUT_ELEMENT.value += `![alt_text](${x.url})`;
    });
});