我想知道是否可以在公共网站上访问/显示存储在谷歌驱动器中的图像等文件。
当前回答
去你的谷歌车道。 右键单击映像文件。 选择Get link。 打开“常规访问”下拉菜单。 选择任何人与链接发布您的图像。 单击复制链接>完成。
你会得到一个像下面这样的URL: https://drive.google.com/file/d/1wMgCWAsqlw0nXcMhCldTbwSznMdXUmBT/view?usp=share_link 您可以看到粗体显示的文件ID。将文件ID放在下面的简单视图链接中: https://drive.google.com/uc?id=FILE ID 结果: https://drive.google.com/uc?id=1wMgCWAsqlw0nXcMhCldTbwSznMdXUmBT
你可以对其他类型的文件采取同样的步骤:MP3, PDF等。
其他回答
特别针对G-Suite用户 . 如第3点所述,您可以使用此URL托管映像
https://drive.google.com/a/domain.com/thumbnail?id=imageID
有以下替换
域名:替换为贵公司的GSuite域名,如皮卡丘 imageID:替换为镜像id /文件id
这里的先决条件是,图像应该通过驱动器共享给目标受众(无论是单独的每个人还是整个组织)
如果你遇到渲染图像大小的问题,请使用下面提到的选项
https://drive.google.com/a/domain.com/thumbnail?id=imageID&sz=w{width}-h{height}
使用以下替换(除了domain和imageID替换)
{width}:以像素为单位写宽度(不带大括号),如300 {height}:以像素为单位(不带大括号)写高度,例如200
牛科技提供的解决方案对我很有效。
http://googledrive.com/host/<folderID>/<filename>
但有两个突出的问题
您不能在驱动器中的同一文件夹中有两个具有相同名称的文件,否则此链接将不起作用。 目前还不清楚,但谷歌似乎计划通过驱动器弃用图像托管。请看下面的链接。 https://support.google.com/richmedia/answer/6098968?hl=en
从谷歌驱动器帮助页面:
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.
以下是来自@ 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">
功能名称: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