title: Github: Upload release assets with Bash
body: <p>I would like to learn about release asset upload through Github API.
  Apart from this
  <a href="https://developer.github.com/v3/repos/releases/" rel="nofollow noreferrer">Github reference</a>,
  I haven't found any recent example. </p>
  
  <p>I created the following Bash script: </p>
  
  <pre><code>#!/bin/sh
  
  ## Make a draft release json with a markdown body
  release='"tag_name": "v1.0.0", "target_commitish": "master", "name": "myapp", '
  body="This is an automatic release\\n====\\n\\nDetails follows"
  body=\"$body\"
  body='"body": '$body', '
  release=$release$body
  release=$release'"draft": true, "prerelease": false'
  release='{'$release'}'
  url="https://api.github.com/repos/$owner/$repo/releases"
  succ=$(curl -H "Authorization: token $perstok" --data $release $url)
  
  ## In case of success, we upload a file
  upload=$(echo $succ | grep upload_url)
  if [[ $? -eq 0 ]]; then
      echo Release created.
  else
      echo Error creating release!
      return
  fi
  
  # $upload is like:
  # "upload_url": "https://uploads.github.com/repos/:owner/:repo/releases/:ID/assets{?name,label}",
  upload=$(echo $upload | cut -d "\"" -f4 | cut -d "{" -f1)
  upload="$upload?name=$theAsset"
  succ=$(curl -H "Authorization: token $perstok" \
       -H "Content-Type: $(file -b --mime-type $theAsset)" \
       --data-binary @$theAsset $upload)
  
  download=$(echo $succ | egrep -o "browser_download_url.+?")  
  if [[ $? -eq 0 ]]; then
      echo $download | cut -d: -f2,3 | cut -d\" -f2
  else
       echo Upload error!
  fi
  </code></pre>
  
  <p>Of course <code>perstok</code>, <code>owner</code> and <code>repo</code> variables export the personal access token, the owner's name and the repo name and <code>theAsset</code> is the asset filename to upload.</p>
  
  <p>Is this the proper way to upload release assets?</p>
  
  <p>Do I need to add an <code>Accept</code> header? I found some examples with</p>
  
  <pre><code>-H "Accept: application/vnd.github.manifold-preview" 
  </code></pre>
  
  <p>but they seem outdated to me.</p>
  
  <p>In case of Windows executables is there a specific media (mime) type?</p>