使用嵌入在iFrame中的 docs.google.com/gview 显示来自Google云端硬盘的文件



我有一个保存在谷歌云端硬盘中的文件。

我想在嵌入在 iframe 中的网站上显示它。

我正在尝试使用谷歌文档查看器,但无法完全使其正常工作。

<iframe src="https://docs.google.com/gview?url={fileUrl}&embedded=true"></iframe>

如果我将文件复制到 s3 存储桶(或 google 云端硬盘以外的其他任何地方)并使用外部链接(例如 https://s3.../filename.ext)作为fileUrl - 它可以工作!

但是我不知道从谷歌云端硬盘使用什么链接。共享和编辑链接不起作用。

  • https://drive.google.com/open?id={fileId}共享链接。
  • https://docs.google.com/document/d/{fileId}/edit打开/编辑链接。

经过一堆谷歌驱动器/文档链接的大量试验和错误,我想通了。

诀窍是使用直接下载链接。 https://drive.google.com/uc?id={fileId}

所以你的 iframe src 应该看起来像这样:

<iframe src="https://docs.google.com/gview?url=https://drive.google.com/uc?id={fileId}&embedded=true"></iframe>

这有效,没有重新加载问题。

https://drive.google.com/file/d/(YOUR_FILE_ID)/预览

最新更新