php - JIRA API attachment names contain the whole paths of the posted files -


i have been working jira api , have seen inconsistent results requests. works , doesn't. last week able post attachments issues fine, old problem occurred: names of attachments contain whole path of posted file, hence attachments can't opened. use json representation post files:

$array = array("file"=>"@filename"); json_encode($array); ... 

this gets file posted problem when it's posted file names in jira this:

/var/www/user/text.text

needless can't opened in jira. had problem before, disappeared, occurred again. don't it. way not using curl request though might recommended in documentation.

i realize question old had similar problem. seems jira doesn't trim filename expected. able fix following. if you're using php >= 5.5.0:

$url = "http://example.com/jira/rest/api/2/issue/123456/attachments"; $headers = array("x-atlassian-token: nocheck");  $attachmentpath = "/full/path/to/file"; $filename = array_pop(explode('/', $attachmentpath));  $cfile = new curlfile($attachmentpath); $cfile->setpostfilename($filename);  $data = array('file'=>$cfile);  $ch = curl_init();  curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_verbose, 1); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_ssl_verifyhost, 0); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_userpwd, "$user:$pass"); curl_setopt($ch, curlopt_postfields, $data);  $result = curl_exec($ch);  $ch_error = curl_error($ch);  if ($ch_error){     echo "curl error: $ch_error"; exit(); } else {     print_r($result); } 

for php <5.5.0 > 5.2.10 (see this bug):

$data = array('file'=>"@{$attachmentpath};filename={$filename}"); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -