Search code examples
reactjsprose-mirrorremirror

Remirror wysiwyg editor image uploadHandler usage


I have started using Remirror library for my much-needed WYSIWYG editor. There I am trying to upload the dropped images on the editor through ImageExtension. To do so I found in the documentation that there is a handler for it - uploadHandler

However, there, the mentioned types are not exported and hence it's becoming much difficult for me to get the required solution.

I particularly need help with a Remirror example that demonstrates how images are uploaded through the uploadHandler()


Solution

  • Posting this here way late because it would have been helpful to me when I found this question.

    new ImageExtension({
        uploadHandler: (
          files: { file: File; progress: (progress: number) => void }[]
        ): DelayedPromiseCreator<ImageAttributes>[] => {
          return files.map((f) => async (props: CommandFunctionProps) => {
            const response = await api.uploadFile(`manage/posts/${postId}/image`, [
              f.file,
            ]);
            return { src: response.result.fileUrl };
          });
        },
      }),