Azure devops repo 使用 Rest Api 从 repo 下载特定文件

Azure devops repo to download a particular file from repo using RestApi

正在尝试使用 RestApi 从 azure devops 存储库下载特定文件 abc.pdf。我能够下载我想要的所需文件,但无法打开下载的 pdf 文件,并且还注意到下载的文件是 repo 中原始文件大小的两倍。

$uri = "https://dev.azure.com/$($organization)/$($project)/_apis/git/repositories/$($repoId)/items?Path=$($appPath)&download=true&api-version=5.1"
$uri = "https://dev.azure.com/$organization/$project/_apis/git/repositories/$repoId/blobs/$($sha1_blob)?download=true&fileName=abc.pdf&api-version=5.1"

$result = Invoke-RestMethod -Uri $uri -Method Get -Headers $header $result | out-file "abc.pdf"

我正在使用 powershell 进行其余调用,并尝试使用上述 2 url 下载文件,它正在下载文件,但文件大小是原始文件的两倍.. 我在这里错过了什么吗?这两个是我用过的restapi url!!! link for git blob from azure devops restapi

link for items to download from azure devops

问题出在单独的 $result | out-file "abc.pdf" 和 pdf 文件的编码上。 而是在 invoke-restmethod 本身中使用了 -outfile 参数,并且成功复制了 pdf 文件。

Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers $header -outfile "abc.pdf"