google-apps-script - 谷歌文档到 base64 字符串
解决方案
您可以将文档转换为 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 字符串之间的区别:
推荐阅读
- javascript - 在我禁止/踢出用户后,我将如何 PM 用户?
- javascript - UIKIT Slider 轮播中心点击
- salesforce-lightning - 嵌套闪电光环迭代
- python-3.x - 是否可以从python调用notepad ++的宏?
- java - 当含义可能从类上下文中清楚时,向字段名称和 getter 添加描述性词
- security - NVD JSON 提要、标签含义及其用途
- python - 如何创建可能包含 Int 或 String 的类型
- javascript - 如何从 gltf 对象获取几何图形
- javascript - 区分具有相同 id 的多个行单元格
- google-app-engine - AttributeError:“资源”对象在谷歌应用引擎中没有属性“列表”