github icon indicating copy to clipboard operation
github copied to clipboard

How would one download a release asset

Open rberger opened this issue 10 years ago • 3 comments
trafficstars

This seems to be an incredible mystery. I can't find any examples for any mechanism to programmatically download a release asset from a private repo.

I had hoped this Gem would have an easy way to do that, but I don't see how to do it here ether.

Any suggestions (or example code)?

Thanks

rberger avatar Feb 18 '15 03:02 rberger

Hi Robert,

The intro paragraph explains how to navigate the api and links to official docs. After reading official documentation for releases, you will find that the code hierarchy corresponds to with the docs. The api has over 200 methods and I took a lot of time to document the api calls with code examples - see release assets

github = Github.new ....
github.repos.releases.assets.get 'owner', 'repo', 'id'

piotrmurach avatar Feb 18 '15 23:02 piotrmurach

Excuse the messy Ruby, but this is what I had to do to wind up downloading a single asset:

def get_asset_download_url(github_user, github_repo, asset_id)
  api = Github.new
  resp = api.repos.releases.assets.get github_user, github_repo, asset_id, accept: 'application/octet-stream'
  return resp.headers.location
end

Two issues I came across was passing application/octet-stream to specify that I wanted a binary, then after that having to handle the redirect response GitHub will give.

Would be nice to see downloading to a file handle as an option.

mjuarez avatar Apr 30 '15 20:04 mjuarez

@rberger I struggled to find it too but it's documented here https://developer.github.com/v3/repos/releases/#response-8 When getting a single asset setting header accept: application/octet-stream will download the asset as binary. Make sure to follow redirects (302).

sarod avatar Sep 07 '15 16:09 sarod