Contribute to this guide

guideCKBox

The CKBox feature lets you easily insert images and links to other files into your content.

This is a premium feature and you need a subscription to use it. You can purchase it here for your open-source CKEditor implementation. Contact us if:

  • CKEditor commercial license is needed for your application.
  • You need the on-premises (self-hosted) version of the service.
  • You have other licensing questions.

You can also sign up for the CKEditor Premium Features 30-day free trial to test the feature.

This feature is enabled by default in all predefined builds for convenience, but the editor will still work properly without activating it.

# How CKBox enhances CKEditor 5

CKBox replaces the basic CKEditor 5 image upload feature. It provides image and file upload and management capabilities:

  • Enables drag & drop uploads of images and other files.
  • Transforms the Image toolbar button, allowing the user to quickly upload and insert an image without opening the CKBox UI.
  • Adds a separate dedicated toolbar button to open the CKBox UI to manage and reuse uploaded files.

With CKBox you no longer need to write server-side code to upload and scale images or manage uploaded files.

To find out more about CKBox, the brand-new file manager, visit the CKBox website and read the dedicated CKBox documentation page.

# Demo

To upload a file using CKBox, use the open file manager toolbar button Open file manager. You can choose more than one file at a time. See detailed instructions in the demo below.

Note that the image toolbar button Insert image will now also upload images into the CKBox file manager. You can access them from the management panel.

Uploading images

To upload an image using CKBox, do the following:

  1. Use the file manager toolbar button to open the CKBox dialog.
  2. Select an image and click the Choose button.

The image will appear in the content.

Note: You can choose more than one file at a time.

Another way to upload images is via the built-in drag & drop mechanism. Simply click the file you need to upload, drag it into the desired position in the editor and drop it. The upload will be done automatically!

Uploading non-embeddable files

Non-embeddable files (like PDFs) are inserted as links. To upload a PDF file, do the following:

  1. Use the file manager toolbar button to open the CKBox dialog.
  2. Select a PDF and click the Choose button.

A link to the file will appear in the content.

This demo only presents a limited set of features. Visit the full-featured editor example to see more in action.

Image files are inserted into the content as images that you can drag around and resize. Non-embeddable files (like PDFs) are inserted as links.

You can also upload images by dragging them into your content. After you drag an image into the editor, it gets uploaded into the CKBox cloud storage and inserted into the content.

# Installation

This feature is enabled by default in all predefined builds. The installation instructions are for developers interested in building their own, custom WYSIWYG editor.

To use this feature in your application, you must first load the CKBox library and then enable CKBox integration in your rich-text editor instance.

The easiest way to load the CKBox library is to include the <script> tag loading the ckbox.js file first:

<script src="https://cdn.ckbox.io/ckbox/latest/ckbox.js"></script>

Then, install the @ckeditor/ckeditor5-ckbox package:

npm install --save @ckeditor/ckeditor5-ckbox

The CKBox feature requires one of the following plugins to be loaded to work correctly:

These plugins are, by default, loaded with the predefined builds, such as ClassicEditor. If you do not have any of them in your editor, install one and add it to your plugin list.

Please also remember, that the CKBox plugin requires the following dependency plugins to work properly: ArticlePluginSet, PictureEditing, ImageUpload, and CloudServices. Except for ImageUpload which is, likewise, available in predefined builds, these need to be added manually.

Finally, add CKBox to your plugin list and configure the feature as needed. An example configuration may look like this:

import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import { ImageUpload, PictureEditing } from '@ckeditor/ckeditor5-image';
import { CloudServices } from '@ckeditor/ckeditor5-cloud-services';
import { CKBox } from "@ckeditor/ckeditor5-ckbox";

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [  ArticlePluginSet, PictureEditing, ImageUpload, CloudServices, CKBox, /* ... */ ],
        toolbar: [ 'ckbox', /* ... */ ], // Depending on your preference.
        ckbox: {
            // Feature configuration.
            // ...
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );

Further in the document the dependency plugins will be ommitted in code listings for clarity.

# Configuration

The feature can be configured via the config.ckbox object.

# Before you start

This is a premium feature. Contact us to receive an offer tailored to your needs.

You can also sign up for the CKEditor Premium Features 30-day free trial to test the feature.

If you already have a valid license, please log into your user dashboard to access the feature settings.

There is a free personal plan. However, it still requires a sign-up.

After you purchase a license, log into the CKEditor Ecosystem customer dashboard to create access credentials, as explained in the CKBox configuration guide.

# Defining upload categories

By default, the CKBox feature maps the uploaded image type to the category configured on the cloud service. You can override this behavior and provide your own mappings via the config.ckbox.defaultUploadCategories configuration option. It is an object, where the keys define categories and their values are the types of images that will be uploaded to these categories. The categories might be referenced either by their name or by their ID. Referencing by ID is future-proof because it will not require configuration changes when a category name changes.

import { CKBox } from '@ckeditor/ckeditor5-ckbox';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ CKBox, /* ... */ ],
        toolbar: [ 'ckbox', /* ... */ ],
        ckbox: {
            defaultUploadCategories: {
                Bitmaps: [ 'bmp' ],
                Pictures: [ 'jpg', 'jpeg' ],
                Scans: [ 'png', 'tiff' ],
                // The category below is referenced by its ID.
                'fdf2a647-b67f-4a6c-b692-5ba1dc1ed87b': [ 'gif' ]
            }
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );

Please keep in mind that if you define your own upload category mappings for a particular image type, only your first found category will be taken into account while finding the appropriate category for the uploaded image. Category mappings configured on the server will not be searched in that case. The image will not be uploaded (and hence inserted into the editor) in the following cases:

  • If you have defined your own category mapping in defaultUploadCategories for the uploaded image type:
    • The category does not exist on the server.
    • The category exists on the server, but the server configuration does not allow the uploaded image type.
  • If you have not defined your own category mapping in defaultUploadCategories for the uploaded image type:
    • There is no category mapping for the uploaded image type on the server.

# Adding the ID for inserted assets

After choosing an asset from the CKBox dialog, it is inserted into the editor content with a unique data-ckbox-resource-id attribute. If you want to disable it and do not want to add this attribute, set the config.ckbox.ignoreDataId option to true:

import { CKBox } from '@ckeditor/ckeditor5-ckbox';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ CKBox, /* ... */ ],
        toolbar: [ 'ckbox', /* ... */ ],
        ckbox: {
            ignoreDataId: true
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );

# Changing the language

By default, the CKBox dialog takes the current language from the editor. If you want to use a different language, you can set the language code in the config.ckbox.language option:

import { CKBox } from '@ckeditor/ckeditor5-ckbox';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ CKBox, /* ... */ ],
        toolbar: [ 'ckbox', /* ... */ ],
        ckbox: {
            language: 'es'
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );

Also, make sure to include the translation file after loading the CKBox library:

<script src="https://cdn.ckbox.io/ckbox/latest/ckbox.js"></script>
<script src="https://cdn.ckbox.io/CKBox/1.2.1/translations/es.js"></script>

# Providing the token URL

The CKBox feature requires the token endpoint URL configured in the config.ckbox.tokenUrl key. If not explicitly provided, the token URL from config.cloudServices.tokenUrl is used instead. If both are provided, the token URL defined in config.ckbox.tokenUrl takes precedence over the config.cloudServices.tokenUrl.

import { CKBox } from '@ckeditor/ckeditor5-ckbox';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ CKBox, /* ... */ ],
        toolbar: [ 'ckbox', /* ... */ ],
        ckbox: {
            tokenUrl: 'https://example.com/cs-token-endpoint'
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );

# Configuring the API service and assets origin

If the cloud service is hosted in your own environment, you should configure the base URL of the API service via the config.ckbox.serviceOrigin and config.ckbox.assetsOrigin options:

import { CKBox } from '@ckeditor/ckeditor5-ckbox';

ClassicEditor
    .create( document.querySelector( '#editor' ), {
        plugins: [ CKBox, /* ... */ ],
        toolbar: [ 'ckbox', /* ... */ ],
        ckbox: {
            serviceOrigin: 'https://example.com/',
            assetsOrigin: 'https://cloud.example.com/',
        }
    } )
    .then( /* ... */ )
    .catch( /* ... */ );

# Common API

The CKBox plugin registers:

  • The 'ckbox' UI button component

  • The 'ckbox' command implemented by the CKBoxCommand

    You can open CKBox by executing the following code:

    editor.execute( 'ckbox' );
    

We recommend using the official CKEditor 5 inspector for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.

# What’s next?

Be sure to check out the comprehensive Image upload overview guide 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 in general.

# Contribute

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