我想知道是否可以在公共网站上访问/显示存储在谷歌驱动器中的图像等文件。
当前回答
然而,这个答案很简单,事实上非常简单,是的,许多人都提到了它,简单地把图像的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)
其他回答
2022年11月面向工作空间(G套件)用户的工作解决方案
一些嵌入代码不显示img,除非查看者登录到gmail,下面的工作就像你的网络主机上的常规图像:
公开分享项目(确保它说“互联网上任何有此链接的人都可以查看):要么图片本身(或图片所在的文件夹),然后按以下方式复制链接
获取文件的ID并在这里插入:
<img src="https://lh3.googleusercontent.com/d/[ID_OF_THE_FILE]">
结果(如果你看到下面的狗,这意味着解决方案仍然有效):
Localmachine
不会显示在MAMP/WAMP类型的本地主机环境,但显示在网页上。
我发现了一个非常有用的api/url:
imageId ->文件ID Width,期望的宽度(不能大于图像分辨率宽度),必须为整数才能工作 高度,期望的高度(不能大于图像分辨率高度),必须为整数才能工作
https://drive.google.com/thumbnail?id=${imageId}&sz=w${width}-h${height}
注意:api/url将保持纵横比,因此它将在第一个维度停止
Con可以禁用javascript在您的浏览器中打开图像文件并在查看页面源或右键单击图像,就会看到图像链接。(事先查看股权偏好)
如果你想在浏览器中查看文件,也可以使用类似于rufo和Torxed提供的方法:
https://drive.google.com/uc?export=view&id={fileId}
功能名称: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