Adding attachment to Jira#39;s api(将附件添加到 Jira 的 api)
问题描述
我正在尝试使用他们的 API 将文件附加到 Jira 案例.我在 Drupal 6 (PHP v.5.0) 中这样做.这是我的代码:
I am trying to attach a file to a Jira case, using their API. I am doing this in Drupal 6 (PHP v.5.0). Here is the code I have:
$ch = curl_init();
$header = array(
'Content-Type: multipart/form-data',
'X-Atlassian-Token: no-check'
);
$attachmentPath = $this->get_file_uploads();
//$attachmentPath comes out to be something like:
//http://localhost/mySite/web/system/files/my_folder/DSC_0344_3.JPG
$data = array('file'=>"@". $attachmentPath, 'filename'=>'test.png');
$url= 'https://mysite.atlassian.net/rest/api/2/issue/20612/attachments/';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->get_jira_headers());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
问题是 $result 显示为 false,而 $ch_error 指出它无法打开文件.这个错误是否与 Drupal 或我如何将我的请求发送到 Jira 有关?顺便说一句,如果我使用绝对路径,就像这样:
The problem is that the $result comes out as false, and the $ch_error states that it couldn't open the file. Does this error have something to do with Drupal or something to do with how I'm sending my request to Jira? BTW, if I use an absolute path, though, like this:
$attachmentPath = 'C:wampwwwmySitewebsitesmySite.netfilesmy_folderDSC_0333.JPG';
上传工作正常.
推荐答案
这应该适合你:
$data = array('file'=>"@". $attachmentPath . ';filename=test.png');
这是 cURL PHP <5.2.10 的错误,您可以在 PHP 错误跟踪器中看到:https://bugs.php.net/bug.php?id=48962(在您看到的评论中,它已被修复)
This was a bug with cURL PHP <5.2.10, you can see this in the PHP bug tracker: https://bugs.php.net/bug.php?id=48962 (And in the comments you see, that it has been fixed)
如果你使用 PHP 5.5.0+,你可以使用这个:
And if you use PHP 5.5.0+ you can use this:
$cfile = new CURLFile($attachmentPath);
$cfile->setPostFilename('test.png');
$data = array('file'=>$cfile);
您也可以在 JIRA 评论中看到这一点:JIRA 评论
You can also see this in a JIRA comment: JIRA Comment
另外我认为你想改变这个:
Also i think you want to change this:
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->get_jira_headers());
为此:
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
这篇关于将附件添加到 Jira 的 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将附件添加到 Jira 的 api


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01