Skip to content

Instantly share code, notes, and snippets.

@furey
Last active August 26, 2026 01:09
Show Gist options
  • Select an option

  • Save furey/6af0c71a34b770a9cbf439f58e41aa00 to your computer and use it in GitHub Desktop.

Select an option

Save furey/6af0c71a34b770a9cbf439f58e41aa00 to your computer and use it in GitHub Desktop.

GitHub Media Dropper via CLI

Note

This is the scripted version of GitHub Media Dropper, which does the same thing by hand.

Upload a media file to GitHub's user-attachments store from the command line and print the embed URL; the same URL you get by dragging the file into a comment box.

Usage

./github-media-dropper.sh path/to/demo.mp4 [owner/repo]

Prints a https://github.com/user-attachments/assets/<uuid> URL ready to paste into a README, issue, or comment.

Videos render as an inline player.

Requirements

  • gh (authenticated) and jq
  • A repository you can push to (defaults to the repo in the current directory); the asset is scoped to it

Caveats

  • The endpoint (uploads.github.com/user-attachments/assets) is unofficial and undocumented, so it may stop working without notice. The manual drag-and-drop is the fallback.
  • A valid asset URL returns 404 to curl; it only resolves in a browser context. Don't use curl to check whether an upload worked.
#!/usr/bin/env bash
set -euo pipefail
# Upload a media file to GitHub's user-attachments store and print the embed
# URL — the same URL you get by dragging the file into a comment box.
#
# ./github-media-dropper.sh path/to/demo.mp4 [owner/repo]
#
# Needs an authenticated `gh` and `jq`. The asset is scoped to a repository
# you can push to; defaults to the repo in the current directory.
FILE="${1:?usage: github-media-dropper.sh <file> [owner/repo]}"
REPOSITORY="${2:-$(gh repo view --json nameWithOwner --jq .nameWithOwner)}"
MIME=$(file -b --mime-type "$FILE")
curl -fsS "https://uploads.github.com/user-attachments/assets?name=$(basename "$FILE")&content_type=$MIME&repository_id=$(gh api "repos/$REPOSITORY" --jq .id)" \
-X POST \
-H "Authorization: Bearer $(gh auth token)" \
-H "Accept: application/json" \
--data-binary "@$FILE" | jq -r .url

Comments are disabled for this gist.