问题
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 ) {
} );
}
} );
回答1:
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.
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 you are using any remote backend such us Dropbox you might need to use the file:getUrl request to obtain the file's URL.
来源:https://stackoverflow.com/questions/35269039/ckfinder-how-to-get-dimension-url-and-dimension-width-height-when-choosing-an