我正在使用CkFinder 3,在成功上传图像后,我需要能够在用户单击“选择”按钮后进行检测:
目前,我正在使用,files:choose
但在cb事件上找不到此信息。
知道如何解决吗?代码示例将不胜感激。
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 ) {
} );
}
} );
以files:choose
事件描述为例。您将获得用户在中选择Backbone.Collection
的文件evt.data.files
。
棘手的部分是从ImageInfo
服务器(使用command:send
请求)获取图像尺寸,因为它需要处理带有承诺的异步代码。
假设您只允许上传图片,则示例代码如下:
// 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' );
} );
} );
} )
如果您使用的是诸如Dropbox这样的任何远程后端,则可能需要使用该file:getUrl
请求来获取文件的URL。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句