github-tools / github-tools/github
Can't post a proper blob for a binary file
- 主要言語
- JavaScript
- スター
- 3.8k
- フォーク
- 809
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- api
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100