[英]Upload file to JIRA REST API with PHP cUrl
I want upload a file to JIRA with REST API. 我想使用REST API将文件上传到JIRA。
My code : 我的代码:
$ch_api = curl_init('https://website.com/rest/api/2/issue/SI-10255/attachments');
curl_setopt($ch_api, CURLOPT_POST, true);
curl_setopt($ch_api, CURLOPT_POSTFIELDS, json_encode(["file" => "@t.txt"]));
curl_setopt($ch_api, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','X-Atlassian-Token:no-check'));
curl_setopt($ch, CURLOPT_USERPWD, "login:password");
curl_setopt($ch_api, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch_api);
curl_close($ch_api);
And i have this error : 而且我有这个错误:
the request was rejected because no multipart boundary was found
And when i add a boundary, the file is not uploaded. 当我添加边界时,文件不会上传。 The response from api was a blank array. api的响应为空数组。
Please help. 请帮忙。
Thanks. 谢谢。
For upload file to JIRA REST API, not use the header "Content-Type:multipart/form-data" 要将文件上传到JIRA REST API,请不要使用标题“ Content-Type:multipart / form-data”
And for the file, use this code : 对于文件,请使用以下代码:
if (function_exists('curl_file_create')) {
$cFile = curl_file_create("file.txt");
} else {
$cFile = '@' . realpath("file.txt");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.