{{< details >}}
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
Markdown 上传是上传到项目的文件,可以在议题、合并请求、代码片段或 wiki 页面中的 Markdown 文本中引用。
上传文件
{{< history >}}
- 在极狐GitLab 15.10 中 GA。功能标志
enforce_max_attachment_size_upload_api
被移除。 - 在极狐GitLab 17.1 中,
full_path
响应属性模式发生了变更。 -
id
属性引入于极狐GitLab 17.3。
{{< /history >}}
将文件上传到指定项目,以便在议题或合并请求描述或评论中使用。
POST /projects/:id/uploads
支持的属性:
Attribute | Type | Required | Description |
---|---|---|---|
file |
string | Yes | 要上传的文件。 |
id |
integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
要从文件系统上传文件,请使用 --form
参数。这会导致 cURL 使用 Content-Type: multipart/form-data
标头发布数据。file=
参数必须指向文件系统上的文件,并以 @
为前缀。
示例请求:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--form "file=@dk.png" "https://gitlab.example.com/api/v4/projects/5/uploads"
示例响应:
{
"id": 5,
"alt": "dk",
"url": "/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png",
"full_path": "/-/project/1234/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png",
"markdown": ""
}
在响应中:
-
full_path
是文件的绝对路径。 -
url
可以在 Markdown 上下文中使用。当使用markdown
中的格式时,链接会被扩展。
列出上传
{{< history >}}
- 引入于极狐GitLab 17.2。
{{< /history >}}
获取按 created_at
降序排序的项目的所有上传。
先决条件:
- 至少是维护者角色。
GET /projects/:id/uploads
支持的属性:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/uploads"
示例响应:
[
{
"id": 1,
"size": 1024,
"filename": "image.png",
"created_at":"2024-06-20T15:53:03.067Z",
"uploaded_by": {
"id": 18,
"name" : "Alexandra Bashirian",
"username" : "eileen.lowe"
}
},
{
"id": 2,
"size": 512,
"filename": "other-image.png",
"created_at":"2024-06-19T15:53:03.067Z",
"uploaded_by": null
}
]
通过 ID 下载上传的文件
{{< history >}}
- 引入于极狐GitLab 17.2。
{{< /history >}}
通过 ID 下载上传的文件。
先决条件:
- 至少是维护者角色。
GET /projects/:id/uploads/:upload_id
支持的属性:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
upload_id |
integer | Yes | 上传的 ID。 |
如果成功,返回 200
和响应体中的上传文件。
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/uploads/1"
通过密钥和文件名下载上传的文件
{{< history >}}
- 引入于极狐GitLab 17.4。
{{< /history >}}
通过密钥和文件名下载上传的文件。
先决条件:
- 至少是访客角色。
GET /projects/:id/uploads/:secret/:filename
支持的属性:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
secret |
string | Yes | 上传的 32 个字符密钥。 |
filename |
string | Yes | 上传的文件名。 |
如果成功,返回 200
和响应体中的上传文件。
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/uploads/648d97c6eef5fc5df8d1004565b3ee5a/sample.jpg"
通过 ID 删除上传的文件
{{< history >}}
- 引入于极狐GitLab 17.2。
{{< /history >}}
通过 ID 删除上传的文件。
先决条件:
- 至少是维护者角色。
DELETE /projects/:id/uploads/:upload_id
支持的属性:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
upload_id |
integer | Yes | 上传的 ID。 |
如果成功,返回 204
状态码,不含任何响应体。
示例请求:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/uploads/1"
通过密钥和文件名删除上传的文件
{{< history >}}
- Introduced in 极狐GitLab 17.4.
{{< /history >}}
通过密钥和文件名删除上传的文件。
先决条件:
- 至少是维护者角色。
DELETE /projects/:id/uploads/:secret/:filename
支持的属性:
Attribute | Type | Required | Description |
---|---|---|---|
id |
integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
secret |
string | Yes | 上传的 32 个字符密钥。 |
filename |
string | Yes | 上传的文件名。 |
如果成功,返回 204
状态码,不含任何响应体。
示例请求:
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/uploads/648d97c6eef5fc5df8d1004565b3ee5a/sample.jpg"