Reputation: 2089
I'm trying to download a single added asset from a release in a private repository but all I get is a 404 response. the download url of the asset is https://github.com/<user>/<repo>/releases/download/20211022/file.json
I've tried several different methods of specifying the username and private access token but all give the same result. When I use the access token to access api.github.com then it seems to work.
I've tried the following formats in curl
curl -i -u <user>:<token> <url>
curl -i "https://<user>:<token>@github.com/ ...."
curl -i -H "Authorization: token <token>" <url>
I can download the source code (zip) from the release, but this has a different url: https://github.com/<user>/<repo>/archive/refs/tags/20211022.zip
What am I doing wrong?
Upvotes: 8
Views: 7437
Reputation: 96
As stated in this document.
You have to use url: /repos/{owner}/{repo}/releases/assets/{asset_id}
not browser_download_url
and set request header to accept application/octet-stream
to download.
And don't forget to add Authorization
header too.
[1]:
Upvotes: 8
Reputation: 1329232
The alternative is to use the GitHub CLI gh
, with the command gh release download
.
Since gh
2.19.0 (Nov. 2022), you can download a single asset with gh release download --output
(after a gh auth login
, for authentication):
In your case:
gh release download --pattern 'file.json' --output file.json
Upvotes: 0