【发布时间】:2016-07-28 04:28:37
【问题描述】:
我想使用 api 将文件从我的系统上传到 github repo 中的目录。是否有任何 api 端点允许我这样做。
【问题讨论】:
标签: github github-api
我想使用 api 将文件从我的系统上传到 github repo 中的目录。是否有任何 api 端点允许我这样做。
【问题讨论】:
标签: github github-api
您应该使用 2013 年 5 月推出的 GitHub CRUD API
它包括:
PUT /repos/:owner/:repo/contents/:path
PUT /repos/:owner/:repo/contents/:path
DELETE /repos/:owner/:repo/contents/:path
【讨论】:
绝对有办法做到这一点。 我就是这样做的;
curl -i -X PUT -H ‘Authorization: token 9xxxxxxxxxxxxxxxxxxxxxxxe2’ -d
‘{“message”: “uploading a sample pdf”,
“content”:”bXkgbm……………………………..”
}’ https://api.github.com/repos/batman/toys/contents/sample.pdf
其中 content 属性是 base64 编码的字符串。我使用这个工具来编码我的 pdf 文件。 https://www.freeformatter.com/base64-encoder.html
注意,“batman”是所有者,“toys”是我的仓库,“contents”必须默认存在,sample.pdf 是您要上传文件的文件名。 简而言之,坚持这种格式:/repos/:owner/:repo/contents/:path 您可以对这些文件中的任何一个运行相同的步骤: PNG (.png) GIF (.gif) JPEG (.jpg) 日志文件 (.log) Microsoft Word (.docx)、Powerpoint (.pptx) 和 Excel (.xlsx) 文档 文本文件 (.txt) PDF (.pdf) 邮编(.zip、.gz)
祝你好运。 顺便说一句,我在这里添加了这些相同的细节:http://www.simplexanswer.com/2019/05/github-api-how-to-upload-a-file/
【讨论】: