简体   繁体   English

Curl 请求将文件添加到 GitHub 版本

[英]Curl request to add file to GitHub release

I am trying to construct a curl request that will allow me to automate the task of attaching a binary to a release in GitHub (so dragging a file into the box).我正在尝试构建一个 curl 请求,这将允许我自动执行将二进制文件附加到 GitHub 中的版本的任务(因此将文件拖入框中)。

From the API docs I can see that we need to obtain the id of the release (which I have already obtained from a prior call):从 API 文档中,我可以看到我们需要获取版本的 id(我已经从之前的电话中获得):

https://developer.github.com/v3/repos/releases/#upload-a-release-asset https://developer.github.com/v3/repos/releases/#upload-a-release-asset

At the moment I get此刻我得到

curl --header {"Content-Type": "application/zip"} --data \'{"name": "path_to_zip_file"} "https://api.github.com/repos/owner/my_repo/releases/:id/assets?access_token=acces_token"

I get a response like with a lot of other我得到了很多其他人的回应

Hello future GitHubber! I bet you're here to remove those nasty inline styles, DRY up these templates and make 'em nice and re-usable, right?`

 <p><strong>We didn't receive a proper request from your browser.</strong></p>

You send JSON payload in your request, but the docs you linked say you need to make a POST request with the raw binary file contents as payload.您在请求中发送 JSON 有效负载,但您链接的文档说您需要使用原始二进制文件内容作为有效负载发出 POST 请求。
Also you miss to set the Content-Type header correctly.您也错过了正确设置Content-Type header 的机会。
Change your curl call to supply the file as payload, add the filename as parameter to the URL and set the header like described in the docs and it should work fine.更改您的curl调用以将文件作为有效负载提供,将文件名作为参数添加到 URL 并设置 header,如文档中所述,它应该可以正常工作。

The resulting command should be something like: curl 'https://api.github.com/repos/owner/my_repo/releases/:id/assets?access_token=acces_token&name=foo.zip' --header 'Content-Type: application/zip' --upload-file test.zip -X POST生成的命令应该类似于: curl 'https://api.github.com/repos/owner/my_repo/releases/:id/assets?access_token=acces_token&name=foo.zip' --header 'Content-Type: application/zip' --upload-file test.zip -X POST

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

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