简体   繁体   English

使用NodeJS和Github API将上传的图像存储到Github

[英]Store an uploaded image to Github using NodeJS and Github API

Been Struggling to try to push an Image to my repo on Github using NodeJS and Github API, I've covered the part of creating the SHA,Commit Tree and everything, the only thing left is to pass the image to the API and saving it as an actual Image (eg test.png) 一直在努力尝试使用NodeJS和Github API将图像推送到我在Github上的仓库中,我已经介绍了创建SHA,Commit Tree和所有内容的部分,剩下的就是将图像传递给API并保存作为实际图像(例如test.png)

What I did so far is retrieving the image like below: 到目前为止,我正在检索如下图像:

reader.onload = (e) => { image = reader.result.split(',')[1] }

Then sending it to the NodeJS server to get Sent to Github, but it's only stored as test.jpg but the content is not an actual Image but just : 然后将其发送到NodeJS服务器以发送到Github,但它仅存储为test.jpg,但内容不是实际的Image,而是:

/9j/4AAQSkZJRgABAQAASABIAAD/4QBARXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqA.....

Any help? 有什么帮助吗?

Based on this blog post , you might have to add ?raw=true to the end of the src url. 根据此博客文章 ,您可能必须在?raw=true src url的末尾添加?raw=true Alternately, I found a hack on a previous SO answer . 或者,我在先前的SO答案上发现了一个黑点。

Okay solved it! 好了,解决了! the only thing that I had to add is to actually convert the base64 content to Binary using this: 我唯一需要添加的是使用以下命令将base64内容实际转换为Binary:

var data = Buffer.from(b64string, 'base64');

And then sending this data to a commit which worked perfectly! 然后将这些数据发送到一个效果很好的提交!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM