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


当前回答

功能名称: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 

其他回答

特别针对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

更新:正如所宣布的,谷歌在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

注意:上述过程的另一种选择是上传谷歌驱动器无法打开/未关联的扩展名的文件。

然而,这个答案很简单,事实上非常简单,是的,许多人都提到了它,简单地把图像的id放在下面的链接https://drive.google.com/uc?export=view&id={fileId}

但不管这有多简单,我还是编写了一个脚本在控制台中运行。 从谷歌驱动器中输入一个完整的可共享链接数组,并将它们转换为上述链接。然后它们可以简单地用作静态地址。

array = ['https://drive.google.com/open?id=0B8kNn6zsgGEtUE5FaGNtcEthNWc','https://drive.google.com/open?id=0B8kNn6zsgGEtM2traVppYkhsV2s','https://drive.google.com/open?id=0B8kNn6zsgGEtNHgzT2x0MThJUlE'] function separateDriveImageId(arr) { for (n=0;n<arr.length;n++){ str = arr[n] for(i=0;i<str.length;i++){ if( str.charAt(i)== '=' ){ var num = i+1; var extrctdStrng = str.substr(num) } } console.log('https://drive.google.com/uc?export=view&id='+extrctdStrng) window.open('https://drive.google.com/uc?export=view&id='+extrctdStrng,'_blank') } } separateDriveImageId(array)

这是唯一的直接链接格式没有重定向(然后一个永久链接),只适用于文件直接可见的谷歌驱动器(例如图像和文档)。 它不受下载限制的影响,您可以使用它在网站上显示图像。

例如共享链接:

https://drive.google.com/file/d/FILE_ID/view?usp=sharing

就变成:

https://lh3.googleusercontent.com/d/FILE_ID

Lh4, lh5和lh6也有作用。

根据这篇博文,目前可行的解决方案是:

<img src=”https://drive.google.com/uc?id=[imageIdGoesHere]" />

在这里测试

https://drive.google.com/uc?id=1m-uOoFzHn4oUGlEsDSEfPBbJ2QhBJzlM

经验证,该系统将于2021年4月26日生效。无需共享文件夹,无需登录。但是公共共享文件是。