github-tools / github

A higher-level wrapper around the Github API. Intended for the browser.
BSD 3-Clause "New" or "Revised" License
3.56k stars 754 forks source link

Write Image to GitRepo #655

Open KlausSchaefers opened 2 years ago

KlausSchaefers commented 2 years ago

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);
}))