我想知道是否可以在公共网站上访问/显示存储在谷歌驱动器中的图像等文件。
当前回答
编辑:截至2020年,这是有效的。以前的大多数答案都过时了。
简单的解决方案
你所要做的就是打开你的文件:
然后,进入你的网页检查器(Chrome, Cmd-Shift-I或Ctrl-Shift-I取决于你的操作系统),并获得链接。将该链接粘贴到浏览器中,它将重定向到另一个链接。复制新的URL。完成了!
重定向的目的是什么?
似乎如果你使用第一个链接,它只能在登录到你的谷歌帐户时才能访问。对其他人没有多大帮助。然而,第二个重定向链接不需要您登录。这就是它背后的基本原理。
我删除了图像中显示的原始文件,但这里有另一个工作示例。
实际上,我已经检查了大约一周前在我的编辑中发布的示例链接,但它似乎不再工作了。看起来这些链接只是临时工作,所以不要在任何生产环境中使用它们。
其他回答
编辑:截至2020年,这是有效的。以前的大多数答案都过时了。
简单的解决方案
你所要做的就是打开你的文件:
然后,进入你的网页检查器(Chrome, Cmd-Shift-I或Ctrl-Shift-I取决于你的操作系统),并获得链接。将该链接粘贴到浏览器中,它将重定向到另一个链接。复制新的URL。完成了!
重定向的目的是什么?
似乎如果你使用第一个链接,它只能在登录到你的谷歌帐户时才能访问。对其他人没有多大帮助。然而,第二个重定向链接不需要您登录。这就是它背后的基本原理。
我删除了图像中显示的原始文件,但这里有另一个工作示例。
实际上,我已经检查了大约一周前在我的编辑中发布的示例链接,但它似乎不再工作了。看起来这些链接只是临时工作,所以不要在任何生产环境中使用它们。
从谷歌驱动器帮助页面:
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.
你可以直接从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
一个解决方法是使用谷歌Drive SDK API获取fileId,然后使用这个Url:
https://drive.google.com/uc?export=view&id= {id}
这将是一个永久链接到您的文件在谷歌驱动器(图像或其他任何东西)。
注:此链接似乎受配额限制。所以不适合公开/大规模共享。