octokit-release-asset-upload
Upload files to a GitHub Release from Node and the browser
⚠️ currently not working in browser
See #1 for more information.
⚠️ uploading with {replace: true} fails
See #2 for more information.
Usage
See options below. The octokitReleaseAssetUpload
method resolves
with the response from the GitHub API
and an additional .release
property which is the release response.
See list of potential errors below.
As Node module
// npm install @gr2m/release-asset-upload
const octokitReleaseAssetUpload = require('@gr2m/release-asset-upload')
const fs = require('fs')
octokitReleaseAssetUpload({
owner: 'octokit-fixture-org',
repo: 'release-assets',
tag: 'v1.0.0',
username: 'your-username',
password: 'secret'
file: fs.createReadStream('example.png'),
name: 'example.png',
contentType: 'image/png',
contentLength: fs.statSync('example.png').size
})
In Browser
<input type="file" id="input">
<script src="octokit-release-asset-upload.min.js"></script>
<script>
octokitReleaseAssetUpload({
owner: 'octokit-fixture-org',
repo: 'release-assets',
tag: 'v1.0.0',
username: 'your-username',
password: 'secret'
file: document.getElementById('input').files[0]
})
</script>
CLI
$ npx octokit-release-asset-upload \
https://github.com/gr2m/octokit-release-asset-upload/releases/tag/v1.0.0 \
./example.png \
--username="your-username" \
--password="secret" \
Options
Option | Type | Description |
---|---|---|
owner
|
String | Required. Name of repository owner (username or organization) |
repo
|
String | Required. Name of repository |
username
|
Object |
Required unless token is set
|
password
|
Object |
Required unless token is set
|
token
|
Object |
Required unless username and password are set
|
file
|
File |
Required.
Node: A file read stream, a String or a Buffer Browser: a File Object |
tag
|
String |
Name of the tag the release is assigned to, e.g. v1.0.0 . Defaults to latest
|
type
|
String |
The file media type. Required if file is a Node read stream, a String, or a Buffer. Defaults to mime type of file otherwise.
|
size
|
Number |
The size of the file in bytes. Required if file is a Node read stream. Defaults to size of file otherwise.
|
name
|
String |
The file name of the asset. Required if file is a Node read stream, a String, or a Buffer. Defaults to name of file otherwise.
|
label
|
String | An alternate short description of the asset. Used in place of the filename on the GitHub release file list UI. |
replace
|
Boolean | When uploading an asset with an existing `name`, the upload will fail with an `already_exists` error. To replace the existing asset instead in that case, set `replace` to `true`. Defaults to `false`. |
Errors
Status | Message | Description |
---|---|---|
400
|
Invalid options | See message for more details |
422
|
Validation Failed |
An asset with the passed name already exists.
Run with replace: true to overwrite it.
|
Similar solutions
- https://github.com/hypermodules/gh-release-assets – Upload assets to a GitHub release
- https://github.com/remixz/publish-release – Create GitHub releases with assets from CLI
- https://github.com/coderaiser/node-putasset – upload asset to release on github
- https://github.com/juliangruber/gh-release-upload – CLI to upload an asset to the latest GitHub Release.
Contribute
All contributions are welcome