Google doc 转 base64 字符串
Google doc to base64 string
我正在使用应用程序脚本。我想获取一个 google 文档并将其转换为 base 64 字符串以 post 到外部应用程序。我一直在阅读文档,但不确定是否可以这样做。
您可以将文档转换为 blob,然后使用内置实用程序对 blob 的字节进行 base64 编码。
function getDocAsBase64String(docId) {
const doc = DocumentApp.openById(docId)
const bytes = doc.getBlob().getBytes()
const base64String = Utilities.base64Encode(bytes)
const base64WebSafeString = Utilities.base64EncodeWebSafe(bytes)
}
以下是相关的 Apps 脚本文档页面:
https://developers.google.com/apps-script/reference/document/document#getBlob()
https://developers.google.com/apps-script/reference/base/blob.html#getBytes()
https://developers.google.com/apps-script/reference/utilities/utilities#base64Encode(Byte)
此页面解释了普通 base64 字符串和网络安全 base64 字符串之间的区别:
我正在使用应用程序脚本。我想获取一个 google 文档并将其转换为 base 64 字符串以 post 到外部应用程序。我一直在阅读文档,但不确定是否可以这样做。
您可以将文档转换为 blob,然后使用内置实用程序对 blob 的字节进行 base64 编码。
function getDocAsBase64String(docId) {
const doc = DocumentApp.openById(docId)
const bytes = doc.getBlob().getBytes()
const base64String = Utilities.base64Encode(bytes)
const base64WebSafeString = Utilities.base64EncodeWebSafe(bytes)
}
以下是相关的 Apps 脚本文档页面:
https://developers.google.com/apps-script/reference/document/document#getBlob() https://developers.google.com/apps-script/reference/base/blob.html#getBytes() https://developers.google.com/apps-script/reference/utilities/utilities#base64Encode(Byte)
此页面解释了普通 base64 字符串和网络安全 base64 字符串之间的区别: