grails - 使用Groovy从OpenLDAP服务器读取和保存二进制图像

标签 grails groovy ldap apacheds

我正在尝试从OpenLDAP服务器保存图像。它为二进制格式,我的所有代码似乎都可以工作,但是图像已损坏。

然后,我尝试在PHP中执行此操作并成功,但是我想在Grails项目中执行此操作。

PHP示例(有效)

<?php
    $conn = ldap_connect('ldap.example.com') or die("Could not connect.\n");
    ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
    $dn = 'ou=People,o=Acme';
    $ldap_rs = ldap_bind($conn) or die("Can't bind to LDAP");
    $res = ldap_search($conn,$dn,"someID=123456789");
    $info = ldap_get_entries($conn, $res);
    $entry = ldap_first_entry($conn, $res);
    $jpeg_data = ldap_get_values_len( $conn, $entry, "someimage-jpeg");
    $jpeg_filename = '/tmp/' . basename( tempnam ('.', 'djp') );
    $outjpeg = fopen($jpeg_filename, "wb");
    fwrite($outjpeg, $jpeg_data[0]);
    fclose ($outjpeg);
    copy ($jpeg_filename, '/some/dir/test.jpg');
    unlink($jpeg_filename);
?>

Groovy示例(不起作用)
def ldap = org.apache.directory.groovyldap.LDAP.newInstance('ldap://ldap.example.com/ou=People,o=Acme')

ldap.eachEntry (filter: 'someID=123456789') { entry ->

    new File('/Some/dir/123456789.jpg').withOutputStream {
        it.write entry.get('someimage-jpeg').getBytes()  // File is created, but image is corrupted (size also doesn't match the PHP version)
    }

}

我如何告诉Apache LDAP库“image-jpeg”实际上是二进制而不是字符串?是否有更好的简单库可用于从LDAP服务器读取二进制数据?通过查看Apache邮件列表someone else had a similar issue,但是我在线程中找不到解决方案。

技术堆栈
  • Grails 2.2.1
  • Apache LDAP API 1.0.0 M16
  • 最佳答案

    您是否检查过图像属性值是否为base-64编码?

    关于grails - 使用Groovy从OpenLDAP服务器读取和保存二进制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15707555/

    相关文章:

    web-services - 为第 3 方 WS 生成 stub 类

    session - 使 Grails 中过滤单元测试的 session 无效

    .net - 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行?

    grails - 如何更改:2006年1月1日星期日BRST 01 00:00:00至2006-01-01 00:00:00.0

    vba - 如何根据Windows登录名使用VBA获取电子邮件地址?

    spring - 通过 Active Directory LDAP 使用 Spring-Security 进行身份验证

    grails - 如何在 GSP 中使用 Spring Security Grails 插件获取 current_user

    hibernate - Grails GORM( hibernate )查询

    groovy - 在 Groovy 中将方法作为参数传递

    grails - 如何使用 g :select 制作带有常量列表项的选择框