javascript - CKFinder how to get dimension URL and Dimension (width/height) when choosing an image (files:choose)? -
i using ckfinder 3, after uploading image need able detect after user click "chose" button:
- file name / id
- url
- width , height original image
at moment using files:choose
cannot find information on cb event.
any idea how solve it? sample of code 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 ) { } ); } } );
taking example files:choose
event description. backbone.collection
of files chosen user in evt.data.files
.
the tricky part obtain image dimensions imageinfo
server (using command:send
request) since requires process asynchronous code promises.
assuming allow images uploaded, example code below:
// listen event. finder.on( 'files:choose', function( evt ) { // iterate on files collection. evt.data.files.foreach( function( file ) { // send command 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 ) { // error handling. return; } // 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 using remote backend such dropbox might need use file:geturl
request obtain file's url.
Comments
Post a Comment