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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。