【问题标题】:How do you convert a base64 image to a base64Binary with Scala如何使用 Scala 将 base64 图像转换为 base64Binary
【发布时间】:2014-03-01 21:09:20
【问题描述】:

我正在使用 Finagle 库在 Scala 中开发网关。此网关位于移动应用程序和我的客户现有网络服务之间。

文件上传方法的 Web 服务描述(托管在 .Net 上)指定预期的文件内容,如下所示:

  <FileContents>base64Binary</FileContents>

在移动端,应用正在使用 PhoneGap 的 FileTransfer 对象将内容上传到网关。这意味着图像以 base64 编码字符串的形式到达网关。

如何使用 Scala 从 base64 编码的字符串转换为 base64Binary?

【问题讨论】:

    标签: scala


    【解决方案1】:

    找到答案through a related question I had.

    我想这个问题可以安全删除,但可能会帮助其他人得到正确答案:

    scala> import org.apache.commons.codec.binary.Base64
    import org.apache.commons.codec.binary.Base64
    
    scala> <FileContents>{Base64.encodeBase64String(bytes)}</FileContents>
    res1: scala.xml.Elem = <FileContents>AQIDBAUGBwgJCg==</FileContents>
    

    【讨论】:

      【解决方案2】:

      如果外部依赖是一个问题,您可以使用this simple encoder/decoder

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-03
        • 1970-01-01
        • 2017-04-04
        • 2015-12-09
        • 2013-12-12
        • 1970-01-01
        相关资源
        最近更新 更多