ekatz
ekatz

Reputation: 1070

Github API - Upload an Image to Repo from base64 array

I've successfully written a json file to a Github Repo from a web session using the Github.js API: https://github.com/michael/github

I'd like to have the user upload an image in the browser, and then save this image to the repo - so I have to save the repo as a 64 bit array (or a Blob representing it). I've tried several options but not having success. Can someone advise how to upload an image using repo.writeFile()?

Upvotes: 0

Views: 199

Answers (1)

ekatz
ekatz

Reputation: 1070

Not the prettiest solution, but this is working for me if I set "encode" to "false" in the repo.writeFile() options.

The string representing the file, as read from a file reader:

window.btoa(window.atob((reader.result.replace(/^(.+,)/, ''))));

Upvotes: 1

Related Questions