[英]I am trying to upload a files to github using node.js
基本上我想使用 github 作为用户生成的内容的文件数据库。
需要帮助使用 node.js 将文件上传到我的 github 存储库
我试着浏览 Github rest API 但文档让我迷路了....有什么帮助吗?
基于 Github API 文档,您需要使用存储库API。
创建新文件或替换存储库中的现有文件。 您必须通过工作流 scope 使用访问令牌进行身份验证才能使用此端点。
所以基本上在代码中,它会是这样的:
const axios = require('axios');
const data = JSON.stringify({
message: 'my commit message',
committer: {
name: <name>,
email: <email>
},
content: Buffer.from('some content').toString('base64')
});
const config = {
method: 'put',
url: 'https://api.github.com/repos/{owner}/{repo}/contents/{path}',
headers: {
'Authorization': 'Bearer {YOUR-TOKEN}',
'Content-Type': 'application/json'
},
data: data
};
axios(config)
.then(response => {
console.log(JSON.stringify(response.data));
})
.catch(error => {
console.log(error);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.