我正在尝试按照远程 API 文档中给出的指南将 .xls 文件上传到 Confluence wiki 页面: https://developer.atlassian.com/confdev/confluence-server-rest-api/confluence-rest-api-examples#ConfluenceRESTAPIExamples-Uploadanattachment
curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" -F "comment=this is my file" "http://localhost:8080/confluence/rest/api/content/3604482/child/attachment" | python -mjson.tool
这就是我正在做的:
curl -v -S -u username:password -X POST -H "X-Atlassian-Token: nocheck" -F "file=@/path/to/local/excelsheet.xls" https://<Confluence server>/display/page
我省略了 Python -mjson.tool,因为它说“无法解码 JSON 对象”,这没有意义,因为我没有发布 JSON。
但是上面的 curl 命令对我不起作用。我在我的控制台上看到了目标页面的 html,但文件没有上传。我尝试以多种方式修改 curl 命令,但没有任何效果。
此外,对于我尝试上传到的页面的 URL,它没有文档中建议的任何 contentID。目标 URL 是一个接受附件并显示上传文件列表的页面。
有人可以指出我哪里错了吗?我对 Curl 没有太多经验。
最佳答案
David Vonka答案是正确的,除了 header “X-Atlassian-Token”值。它必须是“no-check”(而不是“nocheck”)
所以更正的命令是:
curl -v -S -X POST -H "X-Atlassian-Token: no-check" -F "file_0=@<file name>" -F "comment_0=<upload comment>" "http://<server>:<port>/<context>/pages/doattachfile.action?pageId=<page id>&os_username=<username>&os_password=<password>"
注意:用您的值替换所有 <...> 占位符
关于python - 如何使用 curl 将文件上传到 Atlassian Confluence 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22551708/