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


当前回答

以下是来自@ https://productforums.google.com/forum/#!主题/传动/ yU_yF9SI_z0 /讨论

1-上传你的图片

2-右击并选择“获取共享链接”

3-复制链接应该看起来像

https://drive.google.com/open?id=xxxxxxx

4-换开场?加州大学吗?然后像这样使用它

<img src="https://drive.google.com/uc?id=xxxxx">

其他回答

在谷歌驱动器API中有一个文件类型选项。你可以检查它是否被解析成一个有效的图像。我会看一个选项,如果文件类型给我一个无效的图像,然后为文件获取一个新的直接URL。我还没有弄清楚如何做到这一点,但也许这是一个尝试的途径。

Vetea,如果你从图片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 

然而,这个答案很简单,事实上非常简单,是的,许多人都提到了它,简单地把图像的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://productforums.google.com/forum/#!主题/传动/ yU_yF9SI_z0 /讨论

1-上传你的图片

2-右击并选择“获取共享链接”

3-复制链接应该看起来像

https://drive.google.com/open?id=xxxxxxx

4-换开场?加州大学吗?然后像这样使用它

<img src="https://drive.google.com/uc?id=xxxxx">