github-tools / github-tools/github

Can't post a proper blob for a binary file

Offen
#417 1 Kommentar 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
3.8k
Forks
809
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

So I'm trying to do create a blob with `createBlob` for a PNG image from a browser. I've taken a look in the tests and specifically in the [imageBlob fixture](https://github.com/github-tools/github/blob/master/test/fixtures/imageBlob.js), but it doesn't seem to work. You can see an example [here](https://github.com/illia-kolodiazhnyi/github-api-test/blob/barbar/file.png) of what's happening when I try to put the result of `reader.readAsBinaryString` as `createBlob()` parameter.

I've managed to get it working with following steps only:
1. read the image file like `readAsDataURL(image)` to get the Base64 representation
2. remove the MIME type from the string with `content = content.replace(/^(.+,)/, '')`
3. make a change in my local copy of the library (**!**) for `createBlob` funciton:
```
if (typeof content === 'object') {
postBody = content;
} else {
postBody = this._getContentObject(content);
}
```
4. use `createBlob({content: content, encoding: 'base64'})`

Interesting thing is that there used to be a way to do it without interfering the library code ([PR#103](https://github.com/github-tools/github/pull/103), but it's gone with removing the `github.js` file.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.