I am getting a 'Content is not valid Base64' error when posting a certain, very simple, piece of content to github using the API. The content is
unit = $("<li class='s clearfix'></li>");
I am using Base64.urlsafe_encode64 to encode the content.
content = 'unit = $("<li class=\'s clearfix\'></li>")';
url = "https://api.github.com/repos/#{github_user}/#{github_repo}/contents/#{path}"
RestClient.put(url,
{
message: "my message",
content: Base64.urlsafe_encode64(content),
encoding:"base64" }.to_json,
{
params:{access_token:access_token
},accept:'json'}){ |response, request, result|
puts response.code
puts response
}
I am getting this reponse:
422
{"message":"content is not valid Base64",
"documentation_url":"https://developer.github.com/v3/repos/contents/"}
I don't understand how this cannot be valid base64 for github. And it doesn't happen for all submitted data.
content='unit = $("<li class=\'s clearfix\'></li>")'
Base64.urlsafe_decode64(Base64.urlsafe_encode64(content))==content
=> true
What am I doing wrong?