octokit-plugin-create-pull-request
octokit-plugin-create-pull-request copied to clipboard
Base64 files are not well encoded
I have used this plugin to successfully create PRs for many text-based files. I tried to include an image, a file is created with the correct file size, but the content is not correct.
octokit
.createPullRequest({
..
..
changes: [
{
files: {
["path/to/text/file/ok"]:
`JSON.stringify(Ok_text_content)`,
["path/to/png/file/NOK"]: {
content: this.registerForm.value.image_file,
encoding: "base64",
}
},
..
})
Here I ran a diff
to try to figure out the issue, but could not:
For sure, Github could not display the image in PR.
is this.registerForm.value.image_file
a base64 encoded string? How are you encoding it?
Here is a test for this feature as a reference: https://github.com/gr2m/octokit-plugin-create-pull-request/blob/a7472d508e4dae6d750157543951f6e0fb82625a/test/create-binary-file.test.ts#L55-L56
You are correct, I had the extra header
data:image/png;base64,/9j/4...
Fixed by content: this.registerForm.value.image_file.split(',')[1],
Thanks for the hint