繁体   English   中英

如何使用 CURL 上传 github 资产文件

[英]How to upload github asset file using CURL

我想在我的桌面上上传一个名为“hello.txt”的文件到我的 git 存储库,它有一个版本。 我该怎么做呢? 我阅读了 git 文档,但它说的是:

POST https://<upload_url>/repos/:owner/:repo/releases/:id/assets?name 如何在 CURL 中做到这一点。 我不明白这一点。

如何将此文件作为发布资产发布到我的 github 发布? 谢谢

curl \
    -H "Authorization: token $GITHUB_TOKEN" \
    -H "Content-Type: $(file -b --mime-type $FILE)" \
    --data-binary @$FILE \
    "https://uploads.github.com/repos/hubot/singularity/releases/123/assets?name=$(basename $FILE)"

扩展@galeksandrp 的回答,以下是我遇到的一些问题

请注意, --data-binary选项首先将文件内容复制到 RAM,因此,如果您有大文件说接近 2048MB,即 github 版本的绝对限制,出于某种原因,如果 RAM 不够,它会失败curl: option -d: out of memory

解决方法是使用-T file path (不带 @),如果您想查看上传进度,您需要将输出通过管道传输到 cat,例如curl <...the whole command> | cat curl <...the whole command> | cat

所以完整的命令看起来像这样

curl -X POST \
    -H "Content-Length: <file size in bytes>" \
    -H "Content-Type: $(file -b --mime-type $FILE)" \ #from @galeksandrp's answer
    -T "path/to/large/file.ext" \
    -H "Authorization: token $GITHUB_TOKEN" \
    -H "Accept: application/vnd.github.v3+json" \ 
    https://uploads.github.com/repos/<username>/<repo>/releases/<id>/assets?name=<name> | cat

暂无
暂无

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

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