1

https://developer.github.com/enterprise/2.18/v3/repos/contents/#create-or-update-a-file

I am trying to call the above API using github-api library. The API fails with 422, invalid Base 64 encoding.

The library uses MIME type encoding. If I change to Base64.encodeToString(content), github api accepts it.

My question is:

  1. Does github not accept MIME type 64 encoding?
  2. I need to add a header of some kind to say it is not plain 64 but MIME type(which breaks into chunks of 76 characters)?
Hexy
  • 828
  • 14
  • 24

1 Answers1

0

It could be linked to github-api/github-api issue 638:

When we invoke org/kohsuke/github/GHContentBuilder.java#commit() with content length > 57

The API fails with 422, invalid Base 64 encoding

If we have a content 1234567890123456789012345678901234567890123456789012345678 of length 58.

I was able to fix this issue locally by using Base64.getEncoder().encodeToString()

This is however linked to a recent change.

Note that "GitHub Rest API V3 'Other Authentication Methods'" includes:

The API supports Basic Authentication as defined in RFC2617 with a few slight differences.

The main difference is that the RFC requires unauthenticated requests to be answered with 401 Unauthorized responses.
In many places, this would disclose the existence of user data. Instead, the GitHub API responds with 404 Not Found.
This may cause problems for HTTP libraries that assume a 401 Unauthorized response. The solution is to manually craft the Authorization header.

So a MIME encoding might nit be supported by github-api/github-api because of those RFC2617 requirements which are not followed.


Liam Newman from CloudBees comments:

The change you linked (#631 'Remove dependency on apache commons-codec') hasn't been publish in a release yet - if you're you using v1.101 it doesn't have this change.

I'm pretty sure I specifically used the MIME encoding because the non-MIME produced an error. Also, if you look at what comes back from GitHub it is MIME encoded.

See "Decoding base64 while using GitHub API to Download a File"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yeah I raised that issue myself :) I understand the behavior. I am curious why Base64 is ok but not MIME Base64 – Hexy Dec 12 '19 at 06:17
  • @Hexy I always look at the username to check if I am not referencing an issue raise by the OP... but I did not double-check the picture associated with that account! – VonC Dec 12 '19 at 06:40
  • @Hexy Maybe the RFC2045-MIME variant of Base64 is not fully supported, as described in https://stackoverflow.com/a/27951845/6309 – VonC Dec 12 '19 at 06:43
  • Yes, that could be the case. I will reach out to Github directly then. – Hexy Dec 12 '19 at 18:09