我正在使用 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 http://docs.cksource.com/ckfinder3/#!/api/CKFinder.Application-event-files_choose事件描述。你得到Backbone.Collection http://backbonejs.org/#Collection of files http://docs.cksource.com/ckfinder3/#!/api/CKFinder.Models.File由用户选择evt.data.files
.
棘手的部分是获取图像尺寸ImageInfo http://docs.cksource.com/ckfinder3-php/commands.html#command_image_info服务器(使用command:send http://docs.cksource.com/ckfinder3/#!/api/CKFinder.Application-request-command_sendrequest),因为它需要使用 Promise 处理异步代码。
假设您只允许上传图片,示例代码如下:
// 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 http://docs.cksource.com/ckfinder3/#!/api/CKFinder.Application-request-file_getUrl请求获取文件的 URL。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)