From 06f6dc47e305e63aaf904fc8c6b277ce41d56cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Profant?= Date: Sat, 11 Oct 2014 08:59:43 +0200 Subject: [PATCH] Fix upload of base64 encoded files. Fix #69 --- octokit.coffee | 18 ++++++++++-------- octokit.js | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/octokit.coffee b/octokit.coffee index 972615a6..dc6d82fb 100644 --- a/octokit.coffee +++ b/octokit.coffee @@ -791,15 +791,17 @@ makeOctokit = (newPromise, allPromises, XMLHttpRequest, base64encode, userAgent) # Post a new blob object, getting a blob SHA back # ------- @postBlob = (content, isBase64) -> - if typeof (content) is 'string' - # Base64 encode the content if it is binary (isBase64) - content = base64encode(content) if isBase64 - + if isBase64 content = - content: content - encoding: 'utf-8' - - content.encoding = 'base64' if isBase64 + content: content, + encoding: 'base64' + else + if typeof (content) is 'string' + # Base64 encode the content if it is binary (isBase64) + content = base64encode(content) if isBase64 + content = + content: content + encoding: 'utf-8' _request('POST', "#{_repoPath}/git/blobs", content) .then (res) => diff --git a/octokit.js b/octokit.js index 3d033435..ed09ce42 100644 --- a/octokit.js +++ b/octokit.js @@ -776,17 +776,21 @@ }; this.postBlob = function(content, isBase64) { var _this = this; - if (typeof content === 'string') { - if (isBase64) { - content = base64encode(content); - } + if (isBase64) { content = { content: content, - encoding: 'utf-8' + encoding: 'base64' }; - } - if (isBase64) { - content.encoding = 'base64'; + } else { + if (typeof content === 'string') { + if (isBase64) { + content = base64encode(content); + } + content = { + content: content, + encoding: 'utf-8' + }; + } } return _request('POST', "" + _repoPath + "/git/blobs", content).then(function(res) { return res.sha;