340

我想知道是否可以访问/显示存储在公共网站上的 Google Drive 中的图像之类的文件。

4

25 回答 25

236

一种解决方法是获取fileIdwithGoogle Drive SDK API然后使用它Url

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

这将是您在 Google 云端硬盘中的文件(图片或其他任何内容)的永久链接。

注意:此链接似乎受配额限制。所以不适合公共/大规模共享。

于 2012-08-07T23:17:42.950 回答
219

这是简单的视图链接:

https://drive.google.com/uc?id=FILE_ID

例如https://drive.google.com/uc?id=0B9o1MNFt5ld1N3k1cm9tVnZxQjg

您可以对其他文件类型执行相同的操作,例如 MP3、PDF 等。

于 2013-12-19T07:34:51.907 回答
166

更新:正如宣布的那样,谷歌在 2016 年 8 月弃用了这个功能。这是来自谷歌的最终更新以及替代品。

是的,这是可能的。如果您将文件放在公共文件夹中,则可以通过此 URL 获取文件夹中的任何文件:

https://googledrive.com/host/<folderID>/<filename>
于 2012-12-05T02:43:19.933 回答
66

这是来自@ https://productforums.google.com/forum/#!topic/drive/yU_yF9SI_z0/discussion的方法

1-上传你的图片

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

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

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

4-更改open?uc?并像使用它一样使用它

<img src="https://drive.google.com/uc?id=xxxxx">
  • 建议在从网络上引用任何内容时删除http:orhttps:以避免您的服务器出现任何问题。
于 2016-07-04T19:44:31.323 回答
25

更新:正如宣布的那样,谷歌在 2016 年 8 月弃用了此功能。这是来自谷歌的最终更新以及替代品。

根据 2013 年 4 月并使用 Chrome/webkit,以下内容对我有用:

  • 1 创建一个名为“public”的文件夹

  • 2 选择该文件夹,右键单击并共享 > 共享。点击。选择“任何人都可以访问”

  • 3 将文件拖放到文件夹中,然后上传。

  • 4 右键单击​​文件并选择详细信息。Details-Fieldset 中的一行显示“Hosting”。下面是一个网址:

https://googledrive.com/...

  • 将该 URL 拖放到新选项卡中。复制并粘贴网址,然后在您喜欢的任何地方分享或嵌入。

一个限制是,就 HTTP 而言,似乎只有安全的 HTTP 访问是可能的。

更新:
另一个限制是Google 驱动器可以打开的文件将无法以这种方式访问​​。
也就是说,点击“详细信息”不会显示 Google 驱动器的网址。

为了克服这个:

  • 右键单击有问题的文件,然后选择“打开方式>管理应用程序”:

在此处输入图像描述

  • 在此处取消勾选与文件相关的应用程序
  • 可选:重新加载 Google 云端硬盘
  • 右键单击文件并选择“详细信息”
  • 按照步骤 #4 进行操作

注意:上述过程的替代方法是上传带有 Google Drive 无法打开/未关联的扩展名的文件。

于 2013-05-01T19:28:32.670 回答
23

编辑:截至 2020 年,这是有效的。以前的大多数答案都已过时。

简单的解决方案

您所要做的就是打开您的文件:

Google 云端硬盘上的山峰图片

然后,进入您的网络检查器(对于 Chrome,Cmd-Shift-ICtrl-Shift-I取决于您的操作系统)并获取链接。将该链接粘贴到您的浏览器中,它将重定向到另一个链接。复制新网址。完毕!

Web 检查器中显示的图像链接的图像


重定向是为了什么?

如果您使用第一个链接,似乎只有在登录您的 Google 帐户时才能访问它。对其他人帮助不大。但是,第二个重定向链接不需要您登录。这就是它背后的基本原理。


我删除了图像中显示的原始文件,但这里有另一个工作示例。


实际上,我已经检查了大约一周前在编辑中发布的示例链接,但它似乎不再起作用。看起来这些链接只是暂时起作用,所以不要将它们用于任何类型的生产环境。

于 2020-05-11T17:11:24.790 回答
16

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

https://drive.google.com/uc?export=view&id={fileId}
于 2013-01-14T18:15:01.333 回答
8

专门针对 G-Suite 用户。如第 3 点所述,您可以使用此 URL 来托管图像

https://drive.google.com/a/domain.com/thumbnail?id=imageID

有以下替换

  • domain:替换为您公司的 GSuite 域,例如pikachu
  • imageID: 替换为图像 id / 文件 id

这里的先决条件是图像应该通过驱动器共享给目标受众(单独与每个人共享,或者可能在整个组织中共享)

在此处输入图像描述


如果您遇到渲染图像大小的问题,请使用此处提到的以下选项

https://drive.google.com/a/domain.com/thumbnail?id=imageID&sz=w{width}-h{height}

有以下替换(除了domainimageID替换)

  • {width}:以像素为单位写宽度(不带大括号),如300
  • {height}:以像素为单位写出高度(不带大括号),例如200
于 2020-03-05T13:16:41.207 回答
7

我认为这是可能的,但时间很短

您需要做的是将文件的访问控制列表设置为公共只读(或公共读/写)。您可以使用Google Document List API以编程方式执行此操作,也可以通过云端硬盘图像查看器上的“共享”按钮手动执行此操作。

然后,您可以使用 Google Document List API 或Google Drive API(即Java 中的file.getDownloadUrl())以编程方式获取图像的 URL。您还可以通过右键单击 Google Drive 默认图像查看器中的图像手动轻松获取图像链接。

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

基本上,存储在云端硬盘中的图像文件的 URL 应该可以在没有任何身份验证的情况下访问,一旦它被设置为公开共享,但该 URL 会在某个时候发生变化。我们将来可能会找到解决方案,比如提供一个永久 URL,该 URL 将重定向到这些不断变化的 URL,但没有承诺......

于 2012-04-25T10:19:45.883 回答
6

谷歌驱动器帮助页面

要使用云端硬盘托管网页:

  1. 在 drive.google.com 打开云端硬盘并选择一个文件。
  2. 单击页面顶部的共享按钮。
  3. 单击共享框右下角的高级。
  4. 单击更改...。
  5. 选择开 - 在网络上公开,然后单击保存。
  6. 在关闭共享框之前,从“共享链接”下方字段中的 URL 中复制文档 ID。文档 ID 是 URL 中斜线之间的大小写字母和数字字符串。
  7. 共享类似于“www.googledrive.com/host/[doc id]”的 URL,其中 [doc id] 替换为您在第 6 步中复制的文档 ID。

现在任何人都可以查看您的网页。

于 2015-06-20T18:50:31.367 回答
5

2022 年 3 月 Workspace (G Suite) 用户的工作解决方案

除非查看器登录到 gmail,否则某些嵌入代码不会显示 img,以下工作就像您的虚拟主机上的常规图像:

公开共享项目(确保它显示“互联网上的任何人都可以通过此链接查看):图像本身(或图像所在的文件夹)然后按以下方式复制链接

在此处输入图像描述

获取文件的 ID 并在此处插入:
<img src="https://lh3.googleusercontent.com/d/[ID_OF_THE_FILE]">
结果(如果您看到下面的狗,则表示该解决方案仍然有效):
于 2021-11-28T13:09:01.760 回答
5

根据此博客文章,当前有效的解决方案是:

<img src=”https://drive.google.com/uc?id=[imageIdGoesHere]" />

在这里测试

https://drive.google.com/uc?id=1m-uOoFzHn4oUGlEsDSEfPBbJ2QhBJzlM

自 2021 年 4 月 26 日起,此功能已验证有效。无需共享文件夹或登录。但是公开共享的文件是。

于 2020-08-03T08:36:17.553 回答
4

Some of the previous users were close, but they were missing a step here or there.

Here is a video that shows all of the steps.

(Edit 2-Dec-14
The Below information is incorrect when it comes to the new Google Drive. For the New Google Drive follow these instructions.
There are two options you can use,
option 1 you can click the cog on the top right and revert to the old google drive, IF you revert, use the instructions after "End Edit)" .
Option 2 or you can follow the work around I found. If I find a better way than this I will update it, but here is what I have found that works.


The full link will look like this "https://googledrive.com/host/(folder id)
Part one of your link that you need is "https://googledrive.com/host/" for the second half you will need to navigate to the file you would like to share.
Once you are in the folder with the file you would like to share, look at the link above
(Example 1 https://drive.google.com/drive/u/0/#folders/0B3UALYkiLexYSXZlcldoU2NpYXM )
(Example 2 https://drive.google.com/drive/u/0/#folders/0B3UALYkiLexYSXZlcldoU2NpYXM/0B3UALYkiLexYRkNnOVhsUVozRU0)
In both of these above examples, the "Folder ID" you need for sharing is the last group of letters and numbers after the "/" so in example one, it is "0B3UALYkiLexYSXZlcldoU2NpYXM" in example two it is "0B3UALYkiLexYRkNnOVhsUVozRU0"

In the examples I used, example 1 was a folder on my drive, and example 2 was a folder inside that first one, that is why it has the entire first link before the second.
We only need the section after the "/" furthest to the right.


So now that you have your "Folder ID", take the above formula "https://googledrive.com/host/(folder id)"
Example 1 https://googledrive.com/host/0B3UALYkiLexYSXZlcldoU2NpYXM
Example 2 https://googledrive.com/host/0B3UALYkiLexYRkNnOVhsUVozRU0


Great, now that you have this link, open it in a new page. It will direct you to the shared folder. Once there you can either right click on any file and select "Copy link address" or you can click any file in that folder and it will take you to the hosted image, the URL at the top of the page is the hosting URL.


That is the how you do it. It is quite annoying, and personally it seems a whole lot easier to just revert to the old google drive.


I will try to make a new tutorial video ASAP


Let me know if this does not work for you and what problem you are experiencing.


End Edit)

https://www.youtube.com/watch?v=QmN22LMPdDk&feature=youtu.be

Or you can just follow the written ones below.

These pictures go with the ones listed in the steps.

https://googledrive.com/host/0B3UALYkiLexYSXZlcldoU2NpYXM/

  1. Create a Folder on your Google Drive that you would like to use for sharing images.

  2. Select that folder and go to the sharing options. Change the "Who has access" options from "Specific People" to "Public on the web" All images placed in folder will have a hosting link on them shown in Step 4

    (Images : Change Folder Option.png, Change folder option 2.png, and Change folder option 3.png)

  3. place an image in that folder.

  4. select the image you would like to share and look at the details section (usually on right hand side) for a section labeled "Hosting" you should find a link that starts with

    "googledrive.com/host/(random numbers and digits that are the ID for that folder)/(file name)"

    Use that link to share your images. You can use that link to embed them into other websites.

    (Images: Change folder option 4.png and Change folder option share.png)

于 2014-05-18T18:26:39.237 回答
3

Vetea,如果您从图片 URL 获取链接,它不起作用,但如果您从“直接链接”字段获取它应该可以。我已经在多个场合使用和测试过它。

于 2012-09-08T01:24:01.563 回答
3

这是唯一没有重定向的直接链接格式(然后是永久链接),并且仅适用于 Google Drive 上直接可见的文件(例如图像和文档)。
它不受下载限制的影响,您可以使用它在网站上显示图像。

例如分享链接:

https://drive.google.com/file/d/FILE_ID/view?usp=sharing

变成:

https://lh3.googleusercontent.com/d/FILE_ID

lh4、lh5 和 lh6 也可以工作。

于 2021-10-05T13:59:50.237 回答
3

我发现的一个非常有用的 api/url 是:

  • imageId-> 文件 ID
    如果您遇到困难,您可以在哪里找到 fileId 的屏幕截图
  • width,所需的宽度(不能大于图像分辨率宽度),必须是整数才能工作
  • height,所需的高度(不能大于图像分辨率高度),必须是整数才能工作
https://drive.google.com/thumbnail?id=${imageId}&sz=w${width}-h${height}

注意:api/url 将保持纵横比,因此它将在首先满足的任何维度停止

于 2020-08-19T18:38:03.013 回答
1

对于图像,在谷歌查看器中打开图像。IE

方法一

https://docs.google.com/file/d/0Bz7qe_olclTwWDNJRDRmb1pJamM/edit

然后查看源>找到单词“texmex-thumb”,旁边会有链接。

于 2014-04-28T09:30:52.550 回答
1

Google Drive API 中有一个文件类型选项。您也许可以检查它是否解析为有效图像。我会看一个选项,如果文件类型给我一个无效的图像,然后为该文件获取一个新的直接 URL。虽然我还没有弄清楚如何做到这一点,但也许这是一条尝试的道路。

于 2012-04-28T06:33:52.957 回答
1

您可以直接从云端硬盘和 Gmail 中进行操作。就是这样:

1.将图像上传到谷歌驱动器并设置查看权限(可以是公开的或任何有链接的人)

  1. 转到Gmail>撰写。选择附件图标旁边的 +。

  2. 选择驱动器图标(三角形)

  3. 导航到您的图片并右键单击复制图片网址

  4. 根据需要粘贴到网络浏览器或嵌入网页。

于 2013-09-26T13:03:19.707 回答
1

您可以按照以下步骤将您想要的文件嵌入到您的网站。

  1. 在 Google Drive 中查找 PDF 文件
  2. 在 Google Drive 中预览 PDF 文件
  3. 弹出 Google Drive 预览
  4. 使用更多操作菜单并选择嵌入项目
  5. 提供的复制代码
  6. 编辑您要嵌入的 Google 协作平台页面
  7. 打开 HTML 编辑器
  8. 粘贴 Google Drive 预览提供的 HTML 嵌入代码
  9. 使用更新按钮并保存页面

参考资料:https ://www.steegle.com/websites/google-sites-howtos/embed-drive-pdf

于 2020-09-04T05:07:38.347 回答
1

1.将您的图片设置更改为公开。

2.获取它的共享链接。

3.转到本网站并生成直接下载链接。

为我工作!

于 2020-01-01T16:22:48.143 回答
0

Niutech提供的解决方案对我有用,即

http://googledrive.com/host/<folderID>/<filename>

但是有两个悬而未决的问题

  1. 您不能在驱动器的同一文件夹中拥有 2 个同名文件,否则此链接将不起作用。

  2. 目前尚不清楚,但谷歌似乎计划通过驱动器弃用图像托管。请参阅下面的链接。 https://support.google.com/richmedia/answer/6098968?hl=en

于 2014-11-24T17:37:19.927 回答
0

功能名称:goobox

标签:图片托管、正则表达式、URL、谷歌驱动器、保管箱、高级

  • return: string, 返回一个可以直接作为图片来源的字符串URL。
  • 当您在 google drive 或 dropbox 上托管图像时,您不能使用文件的直接 URL 作为图像源。
  • 您需要更改此 URL 以将其直接用作图像源。
  • goobox()将获取图像文件的 URL,并将其更改为直接用作图像源。
  • 重要提示:您需要先检查文件的权限,以及它是否是公开的。
  • 现场示例: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 
于 2020-06-09T16:12:51.023 回答
-1

Con 可以禁用 javascript 在您的浏览器中打开图像文件并在查看页面源代码或右键单击图像,您将看到图像链接。(之前检查共享偏好)

于 2012-12-10T23:59:58.133 回答
-3

然而这个答案很简单,事实上非常简单,是的,很多人都提到过,只需将图像的 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)

于 2016-07-13T19:23:40.997 回答