> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/051-how-can-i-upload-files-from-google-drive.md).

# 我如何从 Google Drive 上传文件？

## 引言

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

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

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

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

由于这类不可预测的变化，Overleaf 很难为 Google 云端硬盘或类似服务提供始终最新且完整记录的 URL 转换流程——这样的指导很快就会过时，从而具有误导性。不过，在本页中我们提供了一种将包含 `**resourcekey**` 参数的 Google 云端硬盘文件共享 URL 转换为可与 Overleaf 一起使用的直接下载 URL 的方法。我们的团队已测试过这一过程，对我们有效，但我们无法保证它对所有人都适用，或对所有人都有效。如果遇到困难，读者首先应尝试查找并查阅其所使用的托管服务提供的最新文档，或寻找最新的文章或 YouTube 视频。

## 在 Google 云端硬盘中共享文件

首先，找出你想上传到 Overleaf 项目的一个存储在 Google 云端硬盘中的文件：

![将 Google 云端硬盘文件上传到 Overleaf](/files/668d9aca9fdcd00fadbae22eeec85f69030c01dd)

接下来，你需要 *共享* 该文件，以便在 Google 云端硬盘之外也能访问它。以下截图拍摄于台式电脑，展示了如何在 Google 云端硬盘中访问文件共享和文件链接选项：

![将 Google 云端硬盘文件上传到 Overleaf](/files/bbbb8c73c715e1c3fb952bcca80f24d93e3f7cec)

在你选择共享文件的选项后，会出现一个 **与他人和群组共享** 对话框（见下图）。你可以在这里选择与特定个人/群组共享该文件，或者让拥有合适 Google 云端硬盘链接的任何人都能访问它。

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

![将 Google 云端硬盘文件上传到 Overleaf](/files/cda0e472e3377713871c4d56040ded20e3e143cd)

## 获取你共享文件的 Google 云端硬盘链接

在选择了首选的链接共享选项后，我们需要获取共享文件的 Google 云端硬盘链接（URL）副本。实现这一点有几种方法：

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

![将 Google 云端硬盘文件上传到 Overleaf](/files/505e5c099ac521fc6c8260ce5d1b84d4bba712a5)

## 为 Overleaf 创建直接下载 URL

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

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

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

要构建下载 URL，我们需要 Google 云端硬盘链接中的以下组成部分：

* `FILE_ID`
* `resourcekey=RESOURCE_KEY`

下面这张图片标出了 `FILE_ID` 和 `RESOURCE_KEY` 组成部分：

![Google 云端硬盘链接 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 云端硬盘下载 URL 的结构](/files/0fb597bcf2b29a090840ba1169a15a050957dc34)

现在你已经准备好将 Google 云端硬盘文件上传到你的 Overleaf 项目中了。

## 将 Google 云端硬盘文件上传到 Overleaf 项目

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

![将 Google 云端硬盘文件上传到 Overleaf](/files/c3ebccd8738297f732b9b16797bb5c37502b2fad)

将下载 URL 粘贴进去，给文件起一个名称，并选择 **创建** ，即可将你的 Google 云端硬盘文件添加（上传）到 Overleaf 项目中。

### 展示 Google 云端硬盘文件上传的视频

下面的视频演示了如何使用下载 URL 将 Google 云端硬盘文件添加到 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://ayakaleaf-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.
