Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload multiple images through react-mde #1220

Open
srosset81 opened this issue Dec 29, 2023 · 0 comments
Open

Upload multiple images through react-mde #1220

srosset81 opened this issue Dec 29, 2023 · 0 comments
Assignees
Labels

Comments

@srosset81
Copy link
Contributor

srosset81 commented Dec 29, 2023

Example in https://codesandbox.io/p/sandbox/react-typescript-icqgv?file=%2Fsrc%2Findex.tsx

Capture d’écran du 2023-12-29 15-02-07

We only need to add this prop:

<MarkdownInput source="pair:description" fullWidth reactMdeProps={{ paste: { saveImage: save } }} />

With the save function looking like this:

const save = async function*(data, file) {
    // Upload "data" to your server
    // Use XMLHttpRequest.send to send a FormData object containing
    // "data"
    // Check this question: https://stackoverflow.com/questions/18055422/how-to-receive-php-image-data-over-copy-n-paste-javascript-with-xmlhttprequest

    // yields the URL that should be inserted in the markdown
    yield "https://picsum.photos/300";

    // returns true meaning that the save was successful
    return true;
  };

The data param is an ArrayBuffer, while file seems to be a regular File.

To make it work, we would only need to move the uploadFile util to the data provider interface.

Estimate time: half a day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant