Hello.
I´ve connected Mantis and Jira with API´s. It works.
But now I cannot send a bug attachemt file from Mantis to Jira via POST.
I´m testing it with Postman and it works. When I create the cURL request with postman, I only have to select the file. When doing it in Mantis I retrieve the file from mantis_bug_file_table where I can find filename, file_type and filesize. But in column diskfile I only have a hexadecimal string that I don´t know how to manage and the column folder is empty.
How can I get the path and use it on the cURL request?
Thanks
Paco
sending attachment via post
Moderators: Developer, Contributor
Re: sending attachment via post
Think you have stored the files in the database. Via the admin section, you can move them to a file location
Re: sending attachment via post
Attachments in bugnotes are stored in mantis_bug_file_table.Think you have stored the files in the database.
What I´m trying to do is write code in a plugin in order to, automatically, the attachments will be sent to Jira by cURL post.
Acctually this plugin is working updating status, some fields and bugnotes (only text) in Jira when users do it in Mantis. But I don´t know how to do it with attachments.
Thanks
Re: sending attachment via post
All required functions you can find in core/file_api.php .
Re: sending attachment via post
Well in the end you need to download the file and attach to your mail.
Not sure if you would like to bypass all authorization checks in Mantis itself but in principle you can get this done by calling this program:
file_download.php?file_id=' . $t_id . '&type=bug'
Once you have file_id of the attachment, you are in business
Not sure if you would like to bypass all authorization checks in Mantis itself but in principle you can get this done by calling this program:
file_download.php?file_id=' . $t_id . '&type=bug'
Once you have file_id of the attachment, you are in business
Re: sending attachment via post
I must not have explained my problem well. Its nothing about sending mails.
It is about send the mantis bug files of an issue to another issue in another system, like I usually do with bugs itselves or bugnotes (test), etc.
Postman generate this code when testing Jira API. And it works:
I usually copy this generated code in my php plugin in Mantis and it works (here there are some hidden items).
But with bug_files, as seen in the example, Postman only generates the name of the file ("Captura.JPG" in the example) and it works. Not in my code.
I think I must add the complete path to the file but I cannot find it in Mantis (netither in 'file_api.php', nor in database)
It is about send the mantis bug files of an issue to another issue in another system, like I usually do with bugs itselves or bugnotes (test), etc.
Postman generate this code when testing Jira API. And it works:
Code: Select all
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://devops.myorg.es/dev-jira/rest/api/2/issue/$JIRAid/attachments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"Captura.JPG\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Authorization: Basic authorizationommited",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Length: 76315",
"Content-Type: application/x-www-form-urlencoded",
"Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; atlassian.xsrf.token=xxxx-xxxx-xxxx-xxxx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_lin; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
"Host: devops.myorg.es",
"Postman-Token: generated by postman",
"User-Agent: PostmanRuntime/7.19.0",
"X-Atlassian-Token: no-check",
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
But with bug_files, as seen in the example, Postman only generates the name of the file ("Captura.JPG" in the example) and it works. Not in my code.
I think I must add the complete path to the file but I cannot find it in Mantis (netither in 'file_api.php', nor in database)
Re: sending attachment via post
if you download the attachment to a temp location, you have the correct path where it is stored. Does not matter if you send it by mail or send a curl link.
So download the file using file_download.php and point you cUrl to that location.
After confirmation that is has been transmitted, you can add cleanup activities.
So download the file using file_download.php and point you cUrl to that location.
After confirmation that is has been transmitted, you can add cleanup activities.