You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attach images/videos to discussions and PRs (like gh --attach) #5111
The latest gh release (2.102) added an --attach flag to gh pr create and gh pr edit:
gh pr create --attach './before.png#Before the fix' --attach ./after.png
It uploads the files to GitHub and puts them in the PR body. If the body already references a file (), that reference is rewritten to the uploaded URL. Otherwise the image is appended. Very handy, especially for agents opening PRs with screenshots.
There's no equivalent in huggingface_hub today. When you drag an image into a discussion or PR comment box on the Hub, the web editor uploads it to https://huggingface.co/uploads and inserts the returned cdn-uploads.huggingface.co URL as markdown. From Python or the hf CLI, the only way to get the same result is to call that endpoint by hand:
URL=$(curl -s -X POST https://huggingface.co/uploads -H "Content-Type: image/png" --data-binary @shot.png)
and then paste  into the description passed to create_discussion or create_commit(..., create_pr=True). It works, but it's undocumented and every script (or agent) has to rediscover it.
Proposal
Python:HfApi.upload_attachment(path) -> str, returning the CDN URL.
CLI: a repeatable --attach FILE[#alt text] option on hf discussions create (including --pr), hf discussions comment and hf discussions edit, with the same behavior as gh: rewrite ./file references in the body, append the others.
Maybe later: the same option on hf upload --create-pr, for the PR description.
Check the file type client-side against what the Hub editor accepts (PNG, JPEG, GIF, WebP, MP4, MOV, WebM, MP3, WAV). SVG is not accepted.
Open question (Hub side)
The upload endpoint doesn't take a token: files uploaded outside the browser end up under .../uploads/noauth/... instead of being tied to the user's account. Before exposing this as a public API, it would be good to have the endpoint accept a regular Authorization: Bearer token so uploads are attributed to the user.
Before exposing this as a public API, it would be good to have the endpoint accept a regular Authorization: Bearer token so uploads are attributed to the user.
Follow-up on the token question: POST /uploads was cookie-only server-side, so a Bearer token was silently ignored and uploads landed under uploads/noauth/.
Authorization: Bearer hf_… (user access token) and OAuth tokens are accepted, and uploads are attributed to the user (uploads/<userId>/…).
The token needs discussion.write, the same permission as posting a comment: classic read/write tokens, fine-grained tokens with discussion.write (global or scoped to any repo/namespace), or OAuth apps with the write-discussions scope. Otherwise it returns a 403.
Anonymous uploads keep working as before.
So HfApi.upload_attachment can just send the usual auth headers.
Activity
julien-c commentedon Oct 9, 2026
it does accept a token!EDIT: shit no it doesn't
gary149 commentedon Oct 12, 2026
yes indeed (lands under uploads/noauth) & the token is ignored (works without it) but it's probably fine.
moon-bot-app commentedon Oct 13, 2026
Follow-up on the token question:
POST /uploadswas cookie-only server-side, so aBearertoken was silently ignored and uploads landed underuploads/noauth/.Hub-side fix: https://github.com/huggingface-internal/moon-landing/pull/20414 (internal). Once it's deployed:
Authorization: Bearer hf_…(user access token) and OAuth tokens are accepted, and uploads are attributed to the user (uploads/<userId>/…).discussion.write, the same permission as posting a comment: classic read/write tokens, fine-grained tokens withdiscussion.write(global or scoped to any repo/namespace), or OAuth apps with thewrite-discussionsscope. Otherwise it returns a 403.So
HfApi.upload_attachmentcan just send the usual auth headers.julien-c commentedon Oct 14, 2026
the server side change has been deployed FYI