如何解码Google :: Apis :: AdminDirectoryV1 :: UserPhoto.photo_data

问题描述 投票:0回答:1

对于google-api-client gem版本0.19.4我尝试使用Google :: Apis :: AdminDirectoryV1获取所有用户及其照片。

当我使用photo_data字段获取用户照片(Google :: Apis :: AdminDirectoryV1 :: UserPhoto)时,我会得到一个十六进制字符串。我无法将其转换为图像?

如何将数据转换为图像。无法在任何地方找到解决方案。

ruby rubygems google-api-client
1个回答
0
投票

the documentation所述,该字段是base64编码的。

使用base64,例如:

require "base64"

enc   = Base64.encode64('Send reinforcements')
                    # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
plain = Base64.decode64(enc)
                    # -> "Send reinforcements"
© www.soinside.com 2019 - 2024. All rights reserved.