我發現了幾個關於如何將附件上載到jira中的問題的例子,但是我還沒有能夠使它們中的任何一個工作。我在Jira社區幫助論壇上發佈了這個問題,但已經過了一個多星期的0回覆,希望這裏的社區能夠提供幫助。Jira附加文件使用PHP和CURL發佈
這裏是我當前的嘗試:
$Jirausername = 'myUsername';
$Jirapassword = 'myPassword';
$ch=curl_init();
$headers = array(
'X-Atlassian-Token: nocheck',
'Content-Type: multipart/form-data'
);
$data = array('file' => "testing.txt");
curl_setopt_array(
$ch,
array(
CURLOPT_URL=>'https://myCompany.net/rest/api/latest/issue/TAG-78/attachments',
CURLOPT_POST=>true,
CURLOPT_VERBOSE=>1,
CURLOPT_POSTFIELDS=>$data,
CURLOPT_SSL_VERIFYHOST=> 0,
CURLOPT_SSL_VERIFYPEER=> 0,
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_HEADER=>false,
CURLOPT_HTTPHEADER=> $headers,
CURLOPT_USERPWD=>"$Jirausername:$Jirapassword"
)
);
$result=curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
var_dump($result);
}
curl_close($ch);
testing.txt是在同一個目錄作爲該文件。我已經卷曲安裝在哪裏,這是託管,可以創建JIRA罰款問題的Web服務器,只是不能似乎上傳attahcments ...
當我運行這個頁面會顯示:
string(0) ""
沒有附件上傳也不用說了。任何想法我做錯了什麼?
編輯:添加賞金,這裏有一些事情我已經嘗試:
- 努力都NOCHECK和NOCHECK
- 努力都@ testing.txt和testing.txt
- 刪除「內容型:多部分/格式數據」
- 完整路徑,例如:
$data = array('file'=>"@C:\xampp\htdocs\Website\testing.txt ,'filename'=>'testing.txt');
- 試過這樣太因爲已知捲曲差錯的:
$data = array('file'=>"@C:\xampp\htdocs\Website\testing.txt" ';filename=testing.txt');
以及上述各項的組合。無論我嘗試什麼,它都不起作用。也確保我是Jira的管理員級用戶。我覺得我的代碼應該工作......但顯然不是。
你可以嘗試將'file'重命名爲'file_contents': '$ data = array('file_contents'=>「testing.txt」);'? – grundic
@grundic完成。輸出改爲:string(2)「[]」仍然沒有文件上傳。 – Lain
[這裏是](https://confluence.atlassian.com/jirakb/how-to-attach-an-attachment-in-a-jira-issue-using-rest-api--699957734.html)標準的一個例子cUrl,但到目前爲止我還沒有發現任何區別。啊,'multipart/form-data'並不是Atlassian的例子。 – grundic