Getting image content from Jira

Graham Tilson November 15, 2019

I'm trying to extract image content from Jira using the REST API. Using the 'attachment' field I can get all the meta data about the image, including filename, size,mimeType, content Url, thumbnail url etc.

But I need to be able to download the image itself. Putting the content url into  a browser downloads the image ok, but only because I happen to logged into Jira.

So I'm using PHP CURL to download the image from this url and I'm hoping that the following code should do it:

$ch = curl_init($url);
$tempPath = '/tmp/jira_' . uniqid(true) ;
$fp = fopen($tempPath, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_USERPWD, "me@mysite.com:$this->_apiKey" );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

curl_exec($ch);
fclose($fp);

I'm using the CURLOPT_USERPWD in the same way I do when using the rest API, but the file is always empty. I'm assuming that this is an authentication issue. Can anybody tell me how I am supposed to authenticate?

0 answers

Suggest an answer

Log in or Sign up to answer