CLI and APIs
Upload an attachment from a bot
Your bot posts a screenshot in a comment, and its token cannot write to the repository. It can still upload an image or a video as an attachment, the same as the web editor does.
2 min read
You need a token that can comment on the repository.
1. Upload the file
Upload the file to attachments/<sha256>.<extension>, where <sha256> is the SHA-256 of its bytes:
FILE=screenshot.png
SHA=$(sha256sum "$FILE" | cut -d ' ' -f 1)
curl -X PUT -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" -H "X-Content-SHA256: $SHA" \
--data-binary "@$FILE" \
https://source.tanstack.com/api/v1/repos/<owner>/<repo>/assets/files/attachments/$SHA.png
Note
The route needs the Content-Length header. curl sends it.
2. Put the file in your comment
Put the url of the answer in the body of your comment:
- For an image:
 - For a video:
<video src="<url>" controls></video>
Done
Your comment shows the image or the video, the same as an attachment from the web editor.
What the route checks
- The file must be an image or a video of the attachment types. Another type gets
415. - The name of the file must be the SHA-256 of its bytes.
- A file that is too large gets
413. - If screening reads the texts of the owner of the token, the file stays hidden until screening shows the text. See While screening reads your text.
Tip
With write access, the same route uploads any asset. See Upload from a script or an agent. Over MCP, upload_asset takes the same attachments, at most 5 MiB each.