octokit-plugin-create-pull-request icon indicating copy to clipboard operation
octokit-plugin-create-pull-request copied to clipboard

Base64 files are not well encoded

Open tarekeldeeb opened this issue 11 months ago • 1 comments

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: pr_bug

For sure, Github could not display the image in PR.

tarekeldeeb avatar Mar 18 '24 15:03 tarekeldeeb

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

gr2m avatar Mar 18 '24 22:03 gr2m

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

tarekeldeeb avatar May 31 '24 20:05 tarekeldeeb