Home Ask Login Register

Developers Planet

Your answer is one click away!

GibboK February 2016

CKFinder how to get dimension URL and Dimension (width/height) when choosing an image (files:choose)?

I am using CkFinder 3, after uploading successfully an image I need to be able to detect after an User click the "Chose" button:

  • file name / id
  • url
  • width and height for original image

At the moment I am using the files:choose but I cannot find this information on the cb event.

Any idea how to solve it? A sample of code would be appreciate thanks.

    CKFinder.modal( {
        connectorPath: 'https://api.mysite.com/lib/ckfinder/core/connector/php/connector.php',
        resizeImages: false, 
        startupFolderExpanded: true,
        chooseFiles: true,
        width: 1000,
        height: 800,
        language: 'en',
        onInit: function( finder ) {
            finder.on( 'files:choose', function( evt ) {
            } );
    } );


jodator February 2016

Taking example from the files:choose event description. You get Backbone.Collection of files chosen by the user in evt.data.files.

The tricky part is to obtain image dimensions from ImageInfo server (using the command:send request) since it requires to process asynchronous code with promises.

Assuming that you only allow Images to be uploaded, example code is below:

// Listen to event.
finder.on( 'files:choose', function( evt ) {
    // Iterate over the files collection.
    evt.data.files.forEach( function( file ) {
        // Send command to the server.
        finder.request( 'command:send', {
            name: 'ImageInfo',
            folder: file.get( 'folder' ),
            params: { fileName: file.get( 'name' ) }
        } ).done( function( response ) {
            // Process server response.
            if ( response.error ) {
                // Some error handling.

            // Log image data:
            console.log( '-------------------' );
            console.log( 'Name:', file.get( 'name' ) );
            console.log( 'URL:', file.getUrl() );
            console.log( 'Dimensions:', response.width + 'x' + response.height );
            console.log( 'Size:', response.size + 'B' );
        } );
    } );
} )

If you are using any remote backend such us Dropbox you might need to use the file:getUrl

Post Status

Asked in February 2016
Viewed 1,331 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life