【问题标题】:Upload file to JIRA REST API with PHP cUrl使用 PHP cUrl 将文件上传到 JIRA REST API
【发布时间】:2018-10-31 15:36:16
【问题描述】:

我想使用 REST API 将文件上传到 JIRA。

我的代码:

$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);

我有这个错误:

the request was rejected because no multipart boundary was found

当我添加边界时,文件没有上传。来自 api 的响应是一个空白数组。

请帮忙。

谢谢。

【问题讨论】:

    标签: rest api curl upload jira


    【解决方案1】:

    对于上传文件到 JIRA REST API,不要使用标题“Content-Type:multipart/form-data”

    对于文件,使用以下代码:

    if (function_exists('curl_file_create')) {
            $cFile = curl_file_create("file.txt");
        } else { 
            $cFile = '@' . realpath("file.txt");
        }
    

    【讨论】:

      猜你喜欢
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多