首页 > 解决方案 > 如何在不更改 File1 的 ID 的情况下将版本从 File1 更新到 File2?

问题描述

这个问题我想了好久还是没能解决,所以特地来请教了。

我正在创建一个基于谷歌脚本的应用程序。我在 Google Drive 中存储了 2 个 PDF 文件:File1 和 File2。

我想通过 File2 更新 File1 的版本而不更改 File1 的 ID。

是否可以使用 Google Script Drive API v2 做到这一点?

标签: google-apps-scriptgoogle-drive-api

解决方案


您可以在 Google Apps 脚本项目中启用 Advanced Drive API 服务,然后使用此代码段更新 Google Drive 中现有文件的内容。

  Drive.Files.update(
    {
      title: "file 1.pdf",
      mimeType: "application/pdf"
    },
    "id of file 1",
    DriveApp.getFileById("id of file 2").getBlob()
  )

推荐阅读