我想知道是否可以在公共网站上访问/显示存储在谷歌驱动器中的图像等文件。


当前回答

在谷歌驱动器API中有一个文件类型选项。你可以检查它是否被解析成一个有效的图像。我会看一个选项,如果文件类型给我一个无效的图像,然后为文件获取一个新的直接URL。我还没有弄清楚如何做到这一点,但也许这是一个尝试的途径。

其他回答

特别针对G-Suite用户 . 如第3点所述,您可以使用此URL托管映像

https://drive.google.com/a/domain.com/thumbnail?id=imageID

有以下替换

域名:替换为贵公司的GSuite域名,如皮卡丘 imageID:替换为镜像id /文件id


这里的先决条件是,图像应该通过驱动器共享给目标受众(无论是单独的每个人还是整个组织)


如果你遇到渲染图像大小的问题,请使用下面提到的选项

https://drive.google.com/a/domain.com/thumbnail?id=imageID&sz=w{width}-h{height}

使用以下替换(除了domain和imageID替换)

{width}:以像素为单位写宽度(不带大括号),如300 {height}:以像素为单位(不带大括号)写高度,例如200

我发现了一个非常有用的api/url:

imageId ->文件ID Width,期望的宽度(不能大于图像分辨率宽度),必须为整数才能工作 高度,期望的高度(不能大于图像分辨率高度),必须为整数才能工作

https://drive.google.com/thumbnail?id=${imageId}&sz=w${width}-h${height}

注意:api/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.

Vetea,如果你从图片URL中获取链接,它不工作,但如果你从“直接链接”字段中获取它,它应该工作。我在多个场合使用并测试过它。

一个解决方法是使用谷歌Drive SDK API获取fileId,然后使用这个Url:

https://drive.google.com/uc?export=view&id= {id}

这将是一个永久链接到您的文件在谷歌驱动器(图像或其他任何东西)。

注:此链接似乎受配额限制。所以不适合公开/大规模共享。