首页 > 解决方案 > 来自 html 的谷歌文档 - 不一致地包括图像

问题描述

我有一个简单的脚本,它使用 NPM 的 googleapis 库将相对较短的 HTML 字符串转换为 google 文档。这有少量的文本和几个<img>标签。我遇到的问题是,有时 1 个图像在最终文档中,有时是不同的图像,有时是三个图像中的 2 个,很少是全部 3 个或没有。

我觉得我错过了等待异步的步骤,但我无法弄清楚它可能是什么。这是我的代码:

const drive = google.drive({ version: 'v2', auth });

        drive.files.insert({
          media: {
            mimeType: 'text/html',
            body: html // html is a simple string of html with some <img> tags
          },
          convert: true
        })
          .then(res => {
       // here I export the file as a PDF and do stuff with that
        });

标签: google-api

解决方案


推荐阅读