我想知道是否可以在公共网站上访问/显示存储在谷歌驱动器中的图像等文件。
当前回答
从谷歌驱动器帮助页面:
To host a webpage with Drive: Open Drive at drive.google.com and select a file. Click the Share button at the top of the page. Click Advanced in the bottom right corner of the sharing box. Click Change.... Choose On - Public on the web and click Save. Before closing the sharing box, copy the document ID from the URL in the field below "Link to share". The document ID is a string of uppercase and lowercase letters and numbers between slashes in the URL. Share the URL that looks like "www.googledrive.com/host/[doc id] where [doc id] is replaced by the document ID you copied in step 6. Anyone can now view your webpage.
其他回答
Vetea,如果你从图片URL中获取链接,它不工作,但如果你从“直接链接”字段中获取它,它应该工作。我在多个场合使用并测试过它。
从谷歌驱动器帮助页面:
To host a webpage with Drive: Open Drive at drive.google.com and select a file. Click the Share button at the top of the page. Click Advanced in the bottom right corner of the sharing box. Click Change.... Choose On - Public on the web and click Save. Before closing the sharing box, copy the document ID from the URL in the field below "Link to share". The document ID is a string of uppercase and lowercase letters and numbers between slashes in the URL. Share the URL that looks like "www.googledrive.com/host/[doc id] where [doc id] is replaced by the document ID you copied in step 6. Anyone can now view your webpage.
如果你想在浏览器中查看文件,也可以使用类似于rufo和Torxed提供的方法:
https://drive.google.com/uc?export=view&id={fileId}
编辑:截至2020年,这是有效的。以前的大多数答案都过时了。
简单的解决方案
你所要做的就是打开你的文件:
然后,进入你的网页检查器(Chrome, Cmd-Shift-I或Ctrl-Shift-I取决于你的操作系统),并获得链接。将该链接粘贴到浏览器中,它将重定向到另一个链接。复制新的URL。完成了!
重定向的目的是什么?
似乎如果你使用第一个链接,它只能在登录到你的谷歌帐户时才能访问。对其他人没有多大帮助。然而,第二个重定向链接不需要您登录。这就是它背后的基本原理。
我删除了图像中显示的原始文件,但这里有另一个工作示例。
实际上,我已经检查了大约一周前在我的编辑中发布的示例链接,但它似乎不再工作了。看起来这些链接只是临时工作,所以不要在任何生产环境中使用它们。
这是唯一的直接链接格式没有重定向(然后一个永久链接),只适用于文件直接可见的谷歌驱动器(例如图像和文档)。 它不受下载限制的影响,您可以使用它在网站上显示图像。
例如共享链接:
https://drive.google.com/file/d/FILE_ID/view?usp=sharing
就变成:
https://lh3.googleusercontent.com/d/FILE_ID
Lh4, lh5和lh6也有作用。