justadev
justadev

Reputation: 45

Upload assets with Octokit

I'm reading the docs at https://docs.github.com/en/rest/reference/releases#upload-a-release-asset but I don't see the page describing how to actually upload the asset?

All I can see is the page saying I should upload as binary but do I actually use octokit to upload?

Upvotes: 3

Views: 1445

Answers (1)

OscarDOM
OscarDOM

Reputation: 856

If you plan to use Octokit, I recommend you to try @octokit/rest.js. This API Client SDK will help you bypass most of the headaches when interacting with GitHub's API.

Checking their docs you can find the equivalent to doing octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets', ...):

octokit.rest.repos.uploadReleaseAsset({
  owner,
  repo,
  release_id,
  name,
  data,
});

Also, in github.com/@octokit/rest.js, I found a example in /tests which probably will be useful to you as guidance: @octokit/rest.js -> release-assets.test.ts:

octokit.request({
          method: "POST",
          url: result.data.upload_url,
          headers: {
            "content-type": "text/plain",
          },
          data: "Hello, world!\n",
          name: "test-upload.txt",
          label: "test",
        });
      })

Upvotes: 1

Related Questions