小编Hea*_*ger的帖子

使用 API 通过 Nodejs 使用 Drive.files.copy 将 Word 文档转换为 Google 文档 在 Google Drive API v3 中进行转换

我正在尝试通过 Node.js 使用 API 将 Word 文档转换为 Google 文档。单词文档已经在一个文件夹中,我只想将它们转换为谷歌文档。我正在使用v3。

v3 文档说,为了使用副本转换文件,您需要将转换参数替换为资源正文中的 mimeType。

我不知道该怎么做?

function listFiles(auth) {
  const drive = google.drive({version: 'v3', auth});
  drive.files.list({
    q: "mimeType = 'application/msword'",
    pageSize: 100,
    fields: 'nextPageToken, files(id, name)',
  }, (err, res) => {
    if (err) return console.log('The API returned an error: ' + err);
    const files = res.data.files;
    if (files.length) {
      console.log('Files:');
      files.map((file) => {
        console.log(`${file.name} (${file.id})`);
        drive.files.copy({
          fileId: file.id,
          'name' : 'Updated File Name',
          'mimeType' : 'application/vnd.google-apps.document'
        })
      });
    } else {
      console.log('No …
Run Code Online (Sandbox Code Playgroud)

javascript ms-word google-docs node.js google-drive-api

3
推荐指数
1
解决办法
1406
查看次数