github-tools / github-tools/github

Can't post a proper blob for a binary file

Open
#417 1 comment 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.8k
Forks
809
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect the createBlob implementation and the test/fixtures/imageBlob.js fixture, then reproduce the browser upload using the issue's PNG example and readAsBinaryString path. Compare the request body and encoding with the working Base64 workaround. Done means a valid binary PNG blob can be created without modifying the library locally, with a regression test covering the supported input.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.