github
github copied to clipboard
Write Image to GitRepo
I am trying to upload an Image to GitHub from the browser. I download the image into a blob, convert the blob into base64 and the use the writeFile method. However, the data never arrives correctly in GitHub.
fetch(url).then(response => response.blob().then(blob => {
let reader = new FileReader();
reader.onloadend = () => {
var base64result = reader.result.substr(reader.result.indexOf(',') + 1);
let fileName = this.getFileName(image.url)
repository.writeFile(this.github.branch, fileName, base64result, 'Quant-UX Export').then(result => {
resolve(result)
})
}
reader.readAsDataURL(blob);
}))