I want to upload files from my system to a directory in github repo using the api .Is there any api endpoint which allows me to do that.
-
For assets: https://stackoverflow.com/questions/5207269/how-to-release-a-build-artifact-asset-on-github-with-a-script – Ciro Santilli OurBigBook.com Sep 17 '18 at 07:06
2 Answers
You should use the GitHub CRUD API which was introduced in .May 2013
It includes:
-
PUT /repos/:owner/:repo/contents/:path
-
PUT /repos/:owner/:repo/contents/:path
-
DELETE /repos/:owner/:repo/contents/:path
-
I am successfully able to upload small files, but the API fails with (502 BAD Gateway) response on bigger files( > 10mb). Is there a solution for using this for bigger files? – pRmdk Dec 08 '21 at 11:33
-
I suspect not. You would have to use Git LFS (https://git-lfs.github.com/, and its API (https://github.com/git-lfs/git-lfs/tree/main/docs/api). – VonC Dec 08 '21 at 13:56
There's deffinitly a way to do it. This is how I did it;
curl -i -X PUT -H ‘Authorization: token 9xxxxxxxxxxxxxxxxxxxxxxxe2’ -d
‘{“message”: “uploading a sample pdf”,
“content”:”bXkgbm……………………………..”
}’ https://api.github.com/repos/batman/toys/contents/sample.pdf
Where the content property is a base64 encoded string of characters. I used this tool to encode my pdf file. https://www.freeformatter.com/base64-encoder.html
Notice, "batman" is the owner, "toys" is my repo, "contents" has to be there by default, and sample.pdf would the name of the file you want to upload your file as. In short, stick to this format: /repos/:owner/:repo/contents/:path And you can run the identical step for any of these files: PNG (.png) GIF (.gif) JPEG (.jpg) Log files (.log) Microsoft Word (.docx), Powerpoint (.pptx), and Excel (.xlsx) documents Text files (.txt) PDFs (.pdf) ZIP (.zip, .gz)
Good luck. Btw, I have these same details added on here: http://www.simplexanswer.com/2019/05/github-api-how-to-upload-a-file/

- 25
- 3