Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GITHub API Issue with file upload

I am trying to upload file to GitHub via GITHub API (http://developer.github.com/v3/repos/contents/). Somehow I am not able to upload file. When I tried to upload existing file it gave me message "{\"message\":\"refs/heads/master expected to be at ee1cd720841a4b5b06a8339c333c56b1748e66f9\",\"documentation_url\":\"http://developer.github.com/v3/repos/contents/\"}". When I went to github and tried to delete file using website it gave me below error. I can do workaround with reset head to previous version and move on. But I am trying to understand what caused this behavior and how can I prevent same in future. Neither Google nor Github Help was able to answer me so looking for something from community. Thanks for looking into it. enter image description here

like image 946
TorontoKid Avatar asked Oct 24 '13 21:10

TorontoKid


People also ask

How do I upload a file to GitHub API?

For uploading the file into GitHub you can go through basic steps: Get the file content using 'fs' module. Encode the content into base64 format. then use GitHub API “https://api.github.com/repos/{owner}/{repo}/contents/{file name}”.

Can we upload file using REST API?

The rules are the same as those applied to the set metadata values REST API. Use Content-Type: application/json to describe this information as a JSON object. File to upload. This must come after the jsonInputParameters parameter.


1 Answers

As Ivan suggested, if we try to create/update files using quick succession using API it causes mentioned behavior. Till issue is fixed we can workaround this by making thread sleep between two request. I hope it will help someone.

like image 106
TorontoKid Avatar answered Sep 22 '22 23:09

TorontoKid