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


当前回答

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

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

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

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

其他回答

如果你想在浏览器中查看文件,也可以使用类似于rufo和Torxed提供的方法:

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

Con可以禁用javascript在您的浏览器中打开图像文件并在查看页面源或右键单击图像,就会看到图像链接。(事先查看股权偏好)

2022年11月面向工作空间(G套件)用户的工作解决方案

一些嵌入代码不显示img,除非查看者登录到gmail,下面的工作就像你的网络主机上的常规图像:

公开分享项目(确保它说“互联网上任何有此链接的人都可以查看):要么图片本身(或图片所在的文件夹),然后按以下方式复制链接

获取文件的ID并在这里插入:

<img src="https://lh3.googleusercontent.com/d/[ID_OF_THE_FILE]">

结果(如果你看到下面的狗,这意味着解决方案仍然有效):

Localmachine

不会显示在MAMP/WAMP类型的本地主机环境,但显示在网页上。

你可以直接从Drive & Gmail来做。方法如下:

1.上传图片到谷歌驱动器并设置查看权限(可以是公共或任何人w/ link)

去Gmail>撰写。选择附件图标旁边的+。 选择驱动器图标(三角形) 导航到您的图像和右键复制图像url 粘贴到网页浏览器或嵌入网页根据需要。

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