user1305989
user1305989

Reputation: 3361

ckeditor 4.5 fileUploadRequest event not firing

I have a textarea with html id "id_textarea".

editor = CKEDITOR.inline( 'id_textarea', {
    filebrowserBrowseUrl : 'browse_url',
    filebrowserUploadUrl : 'upload_url'
});

editor.on( 'fileUploadRequest', function( evt ) {
    console.log("This is not printing");
});

Whenever I try to upload a file, it doesn't print anything to console. Am I doing something wrong?

By the way, my requirement is to add csrf headers before sending a request for which I need to catch some event like fileUploadRequest.

Upvotes: 3

Views: 3704

Answers (1)

f1ames
f1ames

Reputation: 1734

I assume that you are trying to upload files via the Upload tab in the Image Properties dialog. It is provided by the File Browser plugin and fileButton which does not support the fileUploadRequest and fileUploadResponse events (there is already a feature request with a more in-depth description of this case).

If you would like to use these events for some custom request preprocessing, you can use the Upload Image plugin. The configuration process is described in the official docs, but keep in mind that it will work only for dropping or pasting files. Upload via the Image Properties dialog will still be handled by the File Browser plugin which does not support these events.

The important thing here is that since CKEditor 4.5.6, the File Browser plugin uses the CSRF header so it can be probably used on your server side without any modifications in the JavaScript code. So if you are using an older version I suggest updating to 4.5.6 (using e.g. CKBuilder) and trying to integrate with your backend. The CSRF header in the File Browser plugin should be sufficient for your needs.

Here is the header: enter image description here

Upvotes: 6

Related Questions