Adding attachment

How to attach files to jira issues using JIRA::REST module in perl?

2 answers

1 accepted

This widget could not be displayed.
Yew Teck En Atlassian Team Nov 18, 2013

you might want to check out this perl REST client. It has a method to attach file to JIRA: https://metacpan.org/pod/JIRA::Client::Automated

This widget could not be displayed.

I have the same question with JIRA::REST.

With curl the following works:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@c:\test.txt" http://localhost:2990/jira/rest/api/2/issue/Test-27/attachments

I tried Perl with this:

use warnings;
use JIRA::REST;
use Data::Dumper;

# Create REST client URL, userID, Password
my $jira = JIRA::REST->new('http://localhost:2990/jira', 'admin', 'admin');
my $key = "TEST-27";
# Read access to issue works
my $workIssue = $jira->GET("/issue/$key");

# add attachment fails
my $filename = "\@c:\\Test.txt";
print "$filename \n";
my $localIssue = eval {$jira->POST("/issue/$key/attachments", undef, {
    "file" => $filename,
    "Content" => "multipart/form-data",  
    },
    {
    "X-Atlassian-Token" => "nocheck",
      
    });
};
if ($@) {
    print "ERROR: @  $@ \n";
};

The result is always: ERROR: 415 - Unsupported Media Type

I tried several "permutations" of

- naming the file,

- placing the filename or content definition in the data part or in the header part of the POST term

- with or without the "Content" definition

and so on. I never succeeded.

Did someone succeed to add an attachment using JIRA::REST?

P.S: I have seen the recommendation for another Perl REST client, but still would like to know if there is a solution with JIRA::REST?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

255 views 5 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you