CKFinder如何在选择图像(文件:选择)时获取尺寸URL和尺寸(宽度/高度)?

GibboK

我正在使用CkFinder 3,在成功上传图像后,我需要能够在用户单击“选择”按钮后进行检测:

  • 文件名/ ID
  • 网址
  • 原始图像的宽度和高度

目前,我正在使用,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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在OpenCV中获取图像的宽度和高度?

我如何限制选择的图像尺寸

如何在Android中获取显示图像的宽度和高度?

当CSS中的尺寸未知时,如何增加图像的宽度?

从PHAsset获取尺寸(高度和宽度)

获取图像尺寸(高度和宽度)Js或jQuery

从VideoPlayer源URL访问尺寸(宽度/高度)

如何在Woocommerce中选择特定产品时显示不同尺寸

React选择自动尺寸宽度

如何在文件选择中读取(图像数据/尺寸/文件大小/名称)多个图像?

如何限制可裁剪区域的宽度和高度以输出相同尺寸的图像?

如何在AngularJS中获取图像尺寸?

PHP-在上传时获取视频和图像尺寸

如何从Glide获取图像的宽度和高度

一个如何在张量流中沿宽度和高度尺寸交错4D张量?

如何在PHP中验证图像URL的尺寸和格式?

如何在GridView中基于屏幕尺寸设置图像宽度高度

产品尺寸:宽度,高度和深度

以宽高比显示图像,并且所有图像尺寸的高度和宽度均相同

如何根据容器尺寸设置宽度和高度?

即使屏幕尺寸不够大,如何将背景图像缩放到高度和宽度的100%

图像高度为15%,并且当屏幕尺寸小于图像宽度时,缩放高度是多少?

HTML 对部分使用宽度和高度尺寸

缩小尺寸(设置最大宽度和高度)

如何根据不同尺寸的最大宽度和高度计算图像的比例因子

从 URL 获取图像文件尺寸

如何为任何屏幕选择理想的图像尺寸?

如何实现具有固定宽度和动态高度的 Next.js Image 组件以保持图像的尺寸?

Python:如何从 SVG url 获取图像尺寸?