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


当前回答

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

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

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

其他回答

我认为这是可能的,但只是在短时间内

你要做的就是将文件的访问控制列表设置为公共只读(或公共读/写)。您可以通过编程方式使用谷歌文档列表API,或手动通过驱动器图像查看器上的“共享”按钮来实现这一点。

然后,您可以通过使用谷歌文档列表API或使用谷歌驱动器API(即Java中的file.getDownloadUrl())以编程方式获取图像的URL。您还可以通过在谷歌驱动器默认图像查看器中右键单击图像,轻松地手动获取到图像的链接。

问题是,这个链接存在的时间是有限的,所以它会工作一段时间,然后就停止工作了。

基本上,存储在驱动器中的图像文件的URL应该是可以访问的,而不需要任何身份验证,一旦它被设置为公开共享,但URL将在某个时候改变。我们可能会在未来找到一个解决方案,比如提供一个永久的URL,将重定向到这些不断变化的URL,但没有承诺…

你可以直接从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 

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

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

从谷歌驱动器帮助页面:

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.