CKFinder 如何在选择图像时获取尺寸 URL 和尺寸(宽度/高度)(文件:选择)
CKFinder how to get dimension URL and Dimension (width/height) when choosing an image (files:choose)?
我正在使用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
事件描述中获取示例。您将获得用户在 evt.data.files
中选择的文件Backbone.Collection
。
棘手的部分是从服务器ImageInfo
获取图像尺寸(使用 command:send
请求(,因为它需要处理带有 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
请求来获取文件的 URL。
相关文章:
- 选择宽度等于最大选项
- 当有标签时,最大化表中的选择宽度
- 选择“相同宽度”选项
- jQuery UI选择菜单没有't接受百分比宽度
- 选择与自举导轨中的文本框相同的宽度
- 如何正确选择画布宽度
- 如何使用 JavaScript 或 CSS 更改选择标签中的选项宽度
- 如何使用javascript获取图像宽度,高度和文件类型 在IE7,8上,选择文件后
- CKFinder 如何在选择图像时获取尺寸 URL 和尺寸(宽度/高度)(文件:选择)
- Chrome html5 文档类型会更改输入的宽度,但不会更改选择
- Div 宽度根据选择的单选按钮数量调整大小
- 如何在更改选择元素宽度时固定所有元素位置
- 挖空.js使用 jQuery 模板,选择框宽度在更新时变为 0 宽度
- 为什么Safari中相同宽度的“选择和输入”标签在渲染时差异巨大
- 更改farbtastic颜色选择器的宽度对我不起作用
- 如何使用Jquery来选择内联属性宽度值
- 如果没有值,请更改选择框的宽度
- 如何使所有选择元素的宽度为15px
- 如何用jquery改变选项框的宽度(独立于选择宽度)
- 当选择列表中的选项没有't固定为选择宽度时,如果我们选择它,它的值将被修剪