Documentation

Upload

upload.beforeSend

Arguments
xhr ObjectXMLHttpRequest object

This callback triggers before image or file send to upload.

$R('#content', {
    callbacks: {
        upload: {
            beforeSend: function(xhr)
            {
                // send headers for example
                xhr.setRequestHeader('X-CSRF-Token', 'your-token-value');
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onupload: {
            beforeSend: function(xhr)
            {
                // ...
            }
        }
    });
})(Redactor);

upload.start

Arguments
e Object upload event
formData Objectform data object

This callback triggers before image or file upload begins.

$R('#content', {
    callbacks: {
        upload: {
            start: function(e, formData)
            {
                // ...
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onupload: {
            start: function(e, formData)
            {
                // ...
            }
        }
    });
})(Redactor);

upload.complete

Arguments
response Object object with data about uploaded image or file

Triggered when the upload is completed.

$R('#content', {
    callbacks: {
        upload: {
            complete: function(response)
            {
                // upload complete
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onupload: {
            complete: function(response)
            {
                // ...
            }
        }
    });
})(Redactor);

upload.error

Arguments
response Objectobject with data about upload error

Triggered when server-side upload script is telling about the upload error with JSON response:

{
    "error": true,
    "message": "Something went wrong..."
}

Callback example:

$R('#content', {
    callbacks: {
        upload: {
            error: function(response)
            {
                alert(response.message);
            }
        }
    }
});

Listen to the message in a plugin:

(function($R)
{
    $R.add('plugin', 'myplugin', {
        init: function(app)
        {
            // define app
            this.app = app;
        },

        // messages
        onupload: {
            error: function(response)
            {
                // ...
            }
        }
    });
})(Redactor);