Sign up (with export icon)

Base64 image upload adapter

Contribute to this guide Show the table of contents

The Base64 image upload adapter converts inserted images into Base64-encoded strings in the editor output. The images are stored with other content in the database without any server-side processing.

Demo

Copy link

Use the editor below to see the adapter in action. Open the web browser console and click the button below the editor to see the base64–encoded image in the editor output data.

CKEditor 5 offers multiple ways to include images in your rich content. You can choose whichever best suits your needs. Use the classic interface or boost your productivity with advanced image handling.

Paste or drag and drop an image directly into the editor. You can also use the insert image button in the toolbar.

Copy code

Installation

Copy link

After installing the editor, add the feature to your plugin list and toolbar configuration:

import { ClassicEditor, Base64UploadAdapter } from 'ckeditor5';

ClassicEditor
	.create( document.querySelector( '#editor' ), {
		licenseKey: '<YOUR_LICENSE_KEY>', // Or 'GPL'.
		plugins: [ Base64UploadAdapter, /* ... */ ],
		toolbar: [ /* ... */ ]
	} )
	.then( /* ... */ )
	.catch( /* ... */ );
Copy code

Once enabled in the plugin list, the Base64 image upload adapter works out–of–the–box without any additional configuration.

Configuration

Copy link

Configuring allowed file types

Copy link

The allowed file types that can be uploaded should actually be configured in two places:

  • On the client side, in CKEditor 5, restricting image upload through the CKEditor 5 UI and commands.
  • On the server side, in your server configuration.

Client-side configuration

Copy link

Use the image.upload.types configuration option to define the allowed image MIME types that can be uploaded to CKEditor 5.

By default, users can upload jpeg, png, gif, bmp, webp, and tiff files. You can customize this behavior to accept, for example, SVG files (in this case use the svg+xml type).

Server-side configuration

Copy link

It is up to you to implement any filtering mechanisms on your server to restrict the types of images allowed to be uploaded.

What’s next

Copy link

Check out the comprehensive Image upload overview to learn more about different ways of uploading images in CKEditor 5.

See the Image feature guide to find out more about handling images in CKEditor 5 WYSIWYG editor.

Contribute

Copy link

The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-upload.