JIRA API names contain whole paths of published files

I work with the Jira API and see inconsistent results for my queries. Sometimes it works, and sometimes it doesn't. Last week, I was able to publish attachments to questions very well, but now an old problem has arisen: attachment names contain the entire path of the published file, so attachments cannot be opened. I am using json view to publish files:

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

This gets the file, but the problem is when it published the file names to JIRA:

/var/www/user/text.text

Needless to say, it cannot be opened at JIRA. I used to have this problem, then it suddenly disappeared, and now it happened again. I really do not understand. By the way, I do not use curl for this request, although this may be recommended in the documentation.

+1
source share
2 answers

I understand that this question is somewhat old, but I had a similar problem. Jira does not seem to truncate the file name as expected. I was able to fix this as follows. If you are 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, but> 5.2.10 (see this error ):

$data = array('file'=>"@{$attachmentPath};filename={$filename}");
+1
source

Yes, I pointed out the problem at https://jira.atlassian.com/browse/JRA-30765 Adding attachments to JIRA REST, unfortunately, is not as useful as it could be.

Interestingly, the problem is gone - maybe you used your script from another place?

0
source

All Articles