尝试从 Amazon S3 中提取图像(返回 S3ObjectInputStream
)并将其发送到 mandrill email api (采用 base64 编码的字符串)。如何在 Scala 中做到这一点?
最佳答案
我还设法仅使用 Apache commons 来做到这一点;不确定哪种方法更好,但我想我会把这个答案留作记录:
import org.apache.commons.codec.binary.Base64
import org.apache.commons.io.IOUtils
val bytes = IOUtils.toByteArray(stream)
val bytes64 = Base64.encodeBase64(bytes)
val content = new String(bytes64)
关于scala - 如何在 Scala 中将 InputStream 转换为 base64 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14753153/