我想知道是否可以在公共网站上访问/显示存储在谷歌驱动器中的图像等文件。
当前回答
一个解决方法是使用谷歌Drive SDK API获取fileId,然后使用这个Url:
https://drive.google.com/uc?export=view&id= {id}
这将是一个永久链接到您的文件在谷歌驱动器(图像或其他任何东西)。
注:此链接似乎受配额限制。所以不适合公开/大规模共享。
其他回答
从谷歌驱动器帮助页面:
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.
功能名称:goobox
标签:图像托管,regex, URL,谷歌驱动器,dropbox,高级
return: string, Returns a string URL that can be used directly as the source of an image. when you host an image on google drive or dropbox you can't use the direct URL of your file to be an image source. you need to make changes to this URL to use it directly as an image source. goobox() will take the URL of your image file, and change it to be used directly as an image source. Important: you need to check your files' permissions first, and whether it's public. live example: https://ybmex.csb.app/
cconst goobox = (url)=>{
let dropbox_regex = /(http(s)*:\/\/)*(www\.)*(dropbox.com)/;
let drive_regex =/(http(s)*:\/\/)*(www\.)*(drive.google.com\/file\/d\/)/;
if(url.match(dropbox_regex)){
return url.replace(/(http(s)*:\/\/)*(www\.)*/, "https://dl.");
}
if(url.match(drive_regex)){
return `https://drive.google.com/uc?id=${url.replace(drive_regex, "").match(/[\w]*\//)[0].replace(/\//,"")}`;
}
return console.error('Wrong URL, not a vlid drobox or google drive url');
}
let url = 'https://drive.google.com/file/d/1PiCWHIwyQWrn4YxatPZDkB8EfegRIkIV/view'
goobox(URL); // https://drive.google.com/uc?id=1PiCWHIwyQWrn4YxatPZDkB8EfegRIkIV
2022年11月面向工作空间(G套件)用户的工作解决方案
一些嵌入代码不显示img,除非查看者登录到gmail,下面的工作就像你的网络主机上的常规图像:
公开分享项目(确保它说“互联网上任何有此链接的人都可以查看):要么图片本身(或图片所在的文件夹),然后按以下方式复制链接
获取文件的ID并在这里插入:
<img src="https://lh3.googleusercontent.com/d/[ID_OF_THE_FILE]">
结果(如果你看到下面的狗,这意味着解决方案仍然有效):
Localmachine
不会显示在MAMP/WAMP类型的本地主机环境,但显示在网页上。
更新:正如所宣布的,谷歌在2016年8月弃用了此功能。这是谷歌的最后一次更新。
在2013年4月,使用Chrome/webkit,以下对我来说是有效的:
1 .创建一个文件夹,名为。“公共” 2选中该文件夹,右键单击,选择“共享>共享”。点击。选择“任何人都可以访问” 3将文件拖放到文件夹中,并上传。 4右键单击文件,选择“详细信息”。Details-Fieldset中的一行读作“Hosting”。下面是一个url:
https://googledrive.com/..。
拖放该url到一个新的选项卡。复制并粘贴url并共享或嵌入到任何你喜欢的地方。
一个限制是,就HTTP而言,似乎只有安全的HTTP访问是可能的。
更新: 另一个限制是,谷歌驱动器可以打开的文件,将无法以这种方式访问。 也就是说,点击“详细信息”不会显示谷歌驱动器的url。
要克服这个问题:
右键点击有问题的文件,选择“打开>管理应用程序”:
在这里取消文件相关的应用程序 可选:Reload谷歌Drive 右键点击文件,选择“Details” 继续执行步骤#4
注意:上述过程的另一种选择是上传谷歌驱动器无法打开/未关联的扩展名的文件。
在谷歌驱动器API中有一个文件类型选项。你可以检查它是否被解析成一个有效的图像。我会看一个选项,如果文件类型给我一个无效的图像,然后为文件获取一个新的直接URL。我还没有弄清楚如何做到这一点,但也许这是一个尝试的途径。