octokat.js icon indicating copy to clipboard operation
octokat.js copied to clipboard

Cannot fetch files > 1 mb from GitHub API.

Open johncade opened this issue 6 years ago • 2 comments

I get the following error message trying to fetch a .json file that has grown larger than 1mb:

{
  "message":"This API returns blobs up to 1 MB in size. The requested blob is too large to fetch via the API, but you can use the Git Data API to request blobs up to 100 MB in size.",
  "errors":[{"resource":"Blob","field":"data","code":"too_large"}]
}

Is there a workaround that exists for this? Any help would be greatly appreciated, thanks in advance!

johncade avatar Apr 09 '18 17:04 johncade

Any help would be so greatly appreciated.

johncade avatar Apr 13 '18 22:04 johncade

It seems like https://developer.github.com/v3/git/blobs/#get-a-blob allows you to retrieve larger files.

In order to get the sha for the blob, https://developer.github.com/v3/git/ might be useful. I have not had to use Blobs directly, but it might look something like:

  1. Get the branch to find the commit sha
  2. Get the commit for the branch to find the tree sha
  3. Get the tree corresponding to the commit to find subtrees or the blob sha
  4. recurse through subtrees if the JSON file is not at the root of the repository
  5. Get the blob corresponding to the file
  6. base64decode the blob (or maybe use octokat's .readBinary() method)

There are methods on octokat that correspond to each of the GitHub API calls. Examples can be found here: https://github.com/philschatz/octokat.js/blame/master/examples/README.md#L43-L50

Hope that helps!

philschatz avatar Apr 16 '18 02:04 philschatz