guideImport and export

# Overview

The process of saving the data of the document which is in an active collaboration session (i.e. users are connected and writing in the document at the same time) can be challenging. As a result, we have decided to implement a completely new approach which is simpler and safer.

The import and export feature was introduced as an alternative to the autosave plugin. It improves and simplifies the process of synchronizing the data of the document which is saved in your database.

Using this feature, the responsibility for saving the current document data will be transferred from collaborating users to your server. As a result, your server will get the current content of the document from CKEditor Cloud Services.

This feature is in beta version. If you want to enable it, please contact us.

# Benefits of the import and export feature

  • Reduced number of requests to your server. Collaborating users no longer need to send the document data in time intervals.
  • Increased communication security. The synchronization process takes place only between your server and the CKEditor Cloud Services server using an encrypted SSL connection and request signatures.
  • No race condition problem when saving the document content.
  • The process of saving the document data is independent of the network conditions in which the users work.
  • The user does not need to initialize the document. This could impact performance but also security.

# Requirements

  1. Set the required bundleVersion property in the editor configuration. Refer to the Editor configuration section of the Editor bundle documentation for more details.

  2. Upload your editor bundle with the editor configuration to the CKEditor Cloud Services server. Refer to the Editor bundle guide for more information.

  3. Contact us to enable the document storage feature for your environment(s).

# Usage

After successfully uploading your editor bundle to CKEditor Cloud Services you can start using the import and export feature. Implementing this feature involves using two methods available from the REST API level in the Collaboration section.

# Export

Exporting a document means getting the current data of the document from an active collaboration session. It is based on sending a request from your server to CKEditor Cloud Services using the GET /collaborations/{document_id} REST API method.

At this point, using the previously loaded editor bundle, CKEditor Cloud Services converts an active collaboration session to the form (HTML, Markdown, text etc., depending on your editor configuration) which your server will receive in response to the request. Your server should save the received document data in the database.

It is recommended to perform this operation at least once after all users disconnect from the document.

You can achieve this with the Get users connected to the document REST API method or the User disconnected webhook event.

# Import

Importing a document means creating a new collaboration session using the previously saved document data. It is based on sending a request from your server to CKEditor Cloud Services using the POST /collaborations REST API method with the required data in the body:

  "document_id": "your_document_id",
  "bundle_version": "your_editor_id",
  "data": "<p>document_content</p>"

At this point, CKEditor Cloud Services converts the document data sent in the request using the previously loaded editor bundle in bundle_version and creates an active collaborative session for the document_id.

After this operation, users can connect to the created collaboration session and continue working on the loaded document.

# Example

Check an example of an application that uses the import and export feature in Node.js and Express.js.

Also, you can check CKEditor Cloud Services samples repository, where you can find more examples.