Setting up Doka Image Editor with Uppy

For a quick start use the Uppy example project included in the product package as a guideline.

To set up the editor with Uppy we use the useEditorWithUppy plugin which is included in the product package.

Before continuing it's highly recommended to read the JavaScript installation guide as it clarifies important internal functionality of the image editor.

<!DOCTYPE html>

<!-- Uppy styles -->
<link
    rel="stylesheet"
    href="https://transloadit.edgly.net/releases/uppy/v1.8.0/uppy.min.css"
/>

<!-- Doka Image Editor styles -->
<link rel="stylesheet" href="./doka/doka.css" />

<!-- Uppy field -->
<div id="drag-drop-area"></div>

<!-- Uppy scripts -->
<script src="https://transloadit.edgly.net/releases/uppy/v1.8.0/uppy.min.js"></script>

<!-- Doka image editor plugin -->
<script src="./useEditorWithUppy-iife.js"></script>

<script type="module">
    // import Doka Image Editor modules
    import {
        // Image editor
        openEditor,
        createDefaultImageReader,
        createDefaultImageWriter,

        // The plugins we want to use
        plugin_crop,
        plugin_finetune,
        plugin_annotate,

        // The main UI and plugin locale objects
        locale_en_gb,
        plugin_crop_locale_en_gb,
        plugin_finetune_locale_en_gb,
        plugin_annotate_locale_en_gb,

        // Because we use the annotate plugin we also need
        // to import the markup editor locale
        markup_editor_locale_en_gb,

        // Import the default properties
        markup_editor_defaults,
        plugin_finetune_defaults,
    } from './doka/doka.js';

    setPlugins(plugin_crop);

    // Create Uppy instance
    const uppy = Uppy.Core({
        onBeforeFileAdded: useEditorWithUppy(
            // Method to create Doka Image Editor
            openEditor,

            // Doka Image Editor editor options
            {
                imageReader: createDefaultImageReader(),
                imageReader: createDefaultImageWriter(),

                // Set Markup Editor defaults
                ...markup_editor_defaults,

                // Set Finetune plugin defaults
                ...plugin_finetune_defaults,

                // Set locale
                locale: {
                    ...locale_en_gb,
                    ...plugin_crop_locale_en_gb,
                    ...plugin_finetune_locale_en_gb,
                    ...plugin_annotate_locale_en_gb,
                    ...markup_editor_locale_en_gb,
                },
            },

            // Reference to Uppy addFile API
            () => uppy.addFile
        ),
    })
        .use(Uppy.Dashboard, { inline: true, target: '#drag-drop-area' })
        .use(Uppy.Tus, { endpoint: 'https://master.tus.io/files/' });
</script>

Next step

With the editor set up, we can continue to configure the editor to our liking with the available instance properties