I want to upload a file on my desktop called 'hello.txt' to my git repository which has a release. How do I do this? I read the git documentation but it says something like :
POST https://<upload_url>/repos/:owner/:repo/releases/:id/assets?name
. How to do this in CURL. I did not understand this.
How to post this file as a release asset to my github release? Thanks
On GitHub.com, navigate to the main page of the repository. Above the list of files, using the Add file drop-down, click Upload files. Drag and drop the file or folder you'd like to upload to your repository onto the file tree.
Curl is a command-line tool for transferring data specified with URL syntax.
curl \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"https://uploads.github.com/repos/hubot/singularity/releases/123/assets?name=$(basename $FILE)"
Extending upon @galeksandrp's answer, here are some issues I encountered
Note that the --data-binary
option copies the file contents first to RAM, so if you have large files say close to 2048MB i.e. the absolute limit for github releases, for some reason, and if the RAM isn't enough, it fails curl: option -d: out of memory
.
The fix for that is to use -T file path
(without the @) and also on a side note if you want to see the upload progress you need to pipe the output to cat such as curl <...the whole command> | cat
So the complete command would look like this
curl -X POST \
-H "Content-Length: <file size in bytes>" \
-H "Content-Type: $(file -b --mime-type $FILE)" \ #from @galeksandrp's answer
-T "path/to/large/file.ext" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://uploads.github.com/repos/<username>/<repo>/releases/<id>/assets?name=<name> | cat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With