How can I get the binary version of a Github Release Asset using Powershell? -


i following docs github releases, ever returned asset contents.

here powershell script:

$githubrepository = "<repo>" $githubusername = "<username>" $githubapikey = "<apikey>"  # locate latest github release $releaseparams = @{     uri = "https://api.github.com/repos/$githubusername/$githubrepository/releases";     method = 'get';     headers = @{         authorization = 'basic ' + [convert]::tobase64string(             [text.encoding]::ascii.getbytes($githubapikey + ":x-oauth-basic")         );     }     contenttype = 'application/json';     body = (convertto-json $releasedata -compress) }  $result = invoke-restmethod @releaseparams  $tag = $result.tag_name[0] write-host "release $tag found."  $asset = $result.assets[0].url $zipfile = $result.assets[0].name $asset  $releaseassetparams = @{     uri = $asset;     method = 'get';     headers = @{         authorization = 'basic ' + [convert]::tobase64string([text.encoding]::ascii.getbytes($githubapikey + ":x-oauth-basic"));     }     contenttype = 'application/octet-stream'; }  invoke-restmethod @releaseassetparams -outfile $zipfile 

executing script (with variables set correctly), outputs asset contents, not binary (zip) file expected.

is content-type not getting recognized?

you need specify application/octet-stream in accept request header, not content-type request header, because want tell server want accept, not you're sending.

so, need send header this:

accept: application/octet-stream 

and not

content-type: application/octet-stream 

the response api redirect url has actual asset, you'll need make request (this expected behavior). if run problems, let know.


Comments