> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/051-how-can-i-upload-files-from-google-drive.md).

# 如何从 Google Drive 上传文件？

## 引言

位于您的 Google Drive 账户中的图像文件或其他文件资源，可以使用以下方式上传到您的 Overleaf 项目中： [“From External URL” 功能](/latex/zh-cn/zhi-shi-ku/081-how-to-upload-a-file-using-an-external-url.md)——前提是这些 Google Drive 文件已启用文件共享。此外，您还需要创建一个合适的 URL（[直接下载链接](/latex/zh-cn/zhi-shi-ku/081-how-to-upload-a-file-using-an-external-url.md#direct-download-links-28urls29)），可用于将每个 Google Drive 文件添加到您的 Overleaf 项目中：本文将说明如何操作。

从 Google Drive 上传后，相应的 Overleaf 项目文件可随时刷新，以与存储在 Google Drive 中的最新版本重新同步——[下面的视频](#video-showing-google-drive-file-upload) 演示了如何做到这一点。

## 关于 Google 基础服务变更的说明和注意事项

文件托管服务（例如 Google Drive）可以随时更改其服务；尤其是修改链接共享 URL 的结构。例如，Google 在 2021 年宣布了一项 [Google Drive 安全更新](https://support.google.com/a/answer/10685032?hl=en) ，其中新增了 `**resourcekey**` 参数到其文件共享 URL 中。不过，由于这次更新的性质，似乎并非所有用户（或其所有文件）都会立即受到这一变化影响：一些 Google Drive 用户会看到 `**resourcekey**` 参数，而其他用户可能不会。

由于此类不可预测的变化，Overleaf 不可能为 Google Drive 或类似服务持续提供最新且完整记录的 URL 转换流程——这样的指导很快就会过时，从而产生误导。不过，在本页面中，我们提供一种方法，将包含 `**resourcekey**` 参数的 Google Drive 文件共享 URL 转换为您可在 Overleaf 中使用的直接下载 URL。我们的团队已测试过此过程，并且对我们有效，但我们不能保证它对每个人都相关或有效。若遇到困难，读者应首先尝试查找并查阅其所使用的托管服务提供的最新文档，或寻找最新的文章或 YouTube 视频。

## 在 Google Drive 中共享文件

首先，找出您希望上传到 Overleaf 项目中的一个存储在 Google Drive 中的文件：

![将 Google Drive 文件上传到 Overleaf](/files/668d9aca9fdcd00fadbae22eeec85f69030c01dd)

接下来，您需要 *共享* 该文件，以便在 Google Drive 之外也能访问它。下面这张在台式电脑上截取的屏幕截图展示了如何在 Google Drive 中访问文件共享和文件链接选项：

![将 Google Drive 文件上传到 Overleaf](/files/bbbb8c73c715e1c3fb952bcca80f24d93e3f7cec)

在选择共享该文件的选项后，会出现一个 **与人员和群组共享** 对话框（见下文）。在这里，您可以选择与特定个人/群组共享该文件，或将其提供给拥有相应 Google Drive 链接的任何人。

这里，我们将通过将链接共享设置从 **受限** 更改为 **拥有链接的任何人**更改为“拥有链接的任何人”来与任何持有 Google Drive 链接的人共享该文件，如下图所示（截自桌面设备：Windows 笔记本电脑）：

![将 Google Drive 文件上传到 Overleaf](/files/cda0e472e3377713871c4d56040ded20e3e143cd)

## 获取共享文件的 Google Drive 链接

选择首选的链接共享选项后，我们需要获取共享文件的 Google Drive 链接（URL）副本。可以通过几种方式做到这一点：

* 选择 **复制链接** （如果它仍显示在屏幕上），或者
* 右键单击该文件并选择 **获取链接** （见下方截图），然后在弹出框中选择 **复制链接** ，或者
* 选择右侧显示的链接选项（见下方截图），然后在弹出框中选择 **复制链接** 。

![将 Google Drive 文件上传到 Overleaf](/files/505e5c099ac521fc6c8260ce5d1b84d4bba712a5)

## 为 Overleaf 创建直接下载 URL

复制 Google Drive 链接（URL）后，将其粘贴到您选择的文本编辑器中——因为我们将用它来推导出一个 *直接下载 URL* ，用于 Overleaf：Overleaf 可使用该 URL 下载 Google Drive 文件并将其添加到您的项目中。

将 Google Drive 链接（URL）粘贴到文本编辑器后，您应该会看到它具有以下结构：

```
https://drive.google.com/file/d/FILE_ID/view?usp=sharing&resourcekey=RESOURCE_KEY
```

要构造下载 URL，我们需要 Google Drive 链接中的以下组成部分：

* `FILE_ID`
* `resourcekey=RESOURCE_KEY`

下面是一张突出显示 `FILE_ID` 和 `RESOURCE_KEY` 组成部分的图片：

![Google Drive 链接 URL 的结构](/files/b250ea06dbda14f13c629e09a36b586b78ffa54e)

`FILE_ID` 和 `RESOURCE_KEY` 它们是很长的字母数字字符序列，因此复制时请小心，避免遗漏/丢失任何字符。

在提取出 `FILE_ID` 和 `RESOURCE_KEY`之后，请使用以下模板为 Overleaf 构造下载 URL：

```
https://drive.google.com/uc?export=download&id=FILE_ID&resourcekey=RESOURCE_KEY
```

下面是一张突出显示 `FILE_ID` 和 `RESOURCE_KEY` 在构建的下载 URL 中使用这些组成部分的图片：

![Google Drive 下载 URL 的结构](/files/0fb597bcf2b29a090840ba1169a15a050957dc34)

您现在已准备好将 Google Drive 文件上传到您的 Overleaf 项目。

## 将 Google Drive 文件上传到 Overleaf 项目

要使用该下载 URL，请选择 Overleaf 的文件上传功能并选择 **来自外部 URL**:

![将 Google Drive 文件上传到 Overleaf](/files/c3ebccd8738297f732b9b16797bb5c37502b2fad)

，粘贴下载 URL，为文件命名，然后选择 **创建** ，即可将您的 Google Drive 文件添加（上传）到 Overleaf 项目中。

### 展示 Google Drive 文件上传的视频

下面的视频演示了如何使用下载 URL 将 Google Drive 文件添加到 Overleaf 项目中。

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/2PMXTshGJI0Kg2ZtN6iXtk/18d4a3168847009a39f905c9acc45e51/Google_drive_upload.mp4>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/051-how-can-i-upload-files-from-google-drive.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
