Warm tip: This article is reproduced from stackoverflow.com, please click
ckeditor ckeditor5

How to trigger CKEditor 5 image file system dialog from code?

发布于 2020-05-05 12:35:53

How do you trigger the CKEditor 5 insert image file dialog/picker from code? I have the "imageUpload" toolbar button in place and it works, but it's the balloon editor so it's not visible until they select something. I'd like to create my own button that's always visible to make it easier.

Questioner
ron
Viewed
20
Reinmar 2020-02-20 19:36

It's impossible to trigger it from code at any given time. The event must be user-originated (e.g. by a click listener).

If you, however, want to have a button outside the editor which will trigger this logic, you can use the button delivered by CKEditor 5 in ImageUploadUI. Just do this:

const imageUploadButton = editor.ui.componentFactory.create( 'imageUpload', editor.locale );
imageUploadButton.render();
imageUploadButton.element; // The element that you can insert somewhere in your view.