Question
当需要身份验证时,如何以编程方式从 Gitlab 下载文件?
Context
我想以编程方式从 Gitlab 检索 LFS 文件。这API https://docs.gitlab.com/ee/api不幸的是,没有提供正确的终点。
例如,当我运行以下命令时curl
命令:
curl --header 'PRIVATE-TOKEN: XXXXXXXX' 'https://gitlab.company.com/api/v4/projects/4992/repository/files/folder%2Ffilename%2Ebz2?ref=tag-v0.1.0'
我得到一个小的(138 字节)JSON 指针文件,而实际上该文件大约为 4 MB。
我尝试过的
亚特实验室API:get file https://docs.gitlab.com/ee/api/repository_files.html#get-file-from-repository
如上所示,我尝试使用API,但我只得到一个指针文件,而不是存储在LFS系统中的实际对象。
亚特实验室API:获取原始文件 https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
如果我使用获取原始文件方法:
curl --header 'PRIVATE-TOKEN: XXXXXXXX' 'https://gitlab.company.com/api/v4/projects/4992/repository/files/folder%2Ffilename%2Ebz2/raw?ref=tag-v0.1.0'
我再次得到指针,但这次是纯文本。
使用 web 应用端点
I found two https://forum.gitlab.com/t/download-lfs-file-content-not-pointer-with-api/15504 forum posts https://forum.gitlab.com/t/api-download-lfs-file/6297/2关于同样的问题。在这两篇文章中,建议使用 webapp URL 而不是 API 端点。
我认为 webapp URL 是指我在 Gitlab 网页上单击以下载文件的按钮的 URL。
该网址如下所示:
https://gitlab.company.com/group_name/project_name/-/raw/tag-v0.1.0/folder/filename.bz2
但是,如果我尝试使用该 URL 中的私有令牌curl
:
curl --header 'PRIVATE-TOKEN: XXXXXXXX' https://gitlab.company.com/group_name/project_name/-/raw/tag-v0.1.0/folder/filename.bz2
I get:
<html><body>You are being <a href="https://gitlab.company.com/users/sign_in">redirected</a>.</body></html>