How to upload a file using GitHub API #24723
-
Maybe it’s just me, but this guide https://developer.github.com/v3/repos/contents/ is incredibly vague. The objective is to upload a file, preferably .pdf or .png through a curl command. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 2 replies
-
It’s hard to write documentation that is both approachable but also has a good amount of detail to answer whatever questions that people will have. So you’re going to need to understand a few things about the information in the create a file endpoint reference:
I’m also going to be using HTTPie instead of curl because it makes JSON REST API interactions much easier. (And I was never very good at using curl for things 😀) I used the following command:
which resulted in the response:
and generated this commit. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Maybe it will help someone:
Tested on PHP 7. |
Beta Was this translation helpful? Give feedback.
-
what is
To upload a new file do you still need it? My problem is that with HTTPFul i manage to put the zip file into github repo but the the file is corrupt, when i I do git pull and try to unzip the file it say unsupported format. and the size of the file is also just 4K. Here is my code
Any help/suggestion will be appreciated thanks |
Beta Was this translation helpful? Give feedback.
-
Can anyone please show this using postman or Node.js . |
Beta Was this translation helpful? Give feedback.
-
I’m trying to use the script above this comment but felt like commenting the solution to this problem since it was never listed. Basically, you have to get the sha from your existing file. In PHP, this is done using the sha1_file() method.
|
Beta Was this translation helpful? Give feedback.
-
For those looking for this solution, this is for a public folder and only sends the name of the file. |
Beta Was this translation helpful? Give feedback.
-
Also, the curl_init must specify the user, then the repository and, after contents, specify the file path. |
Beta Was this translation helpful? Give feedback.
-
couldn’t able to upload images. |
Beta Was this translation helpful? Give feedback.
It’s hard to write documentation that is both approachable but also has a good amount of detail to answer whatever questions that people will have.
So you’re going to need to understand a few things about the information in the create a file endpoint reference:
:
I’m also going to be using HTTPie instead of curl because it makes JSON REST API interactions much easier. (And I was never very good at using curl for things 😀)
I used the following command: