Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

attach file in confluence

Vidya Shevale November 5, 2018

Hello team

I am using PHP Curl to attach a file. But I am getting error Unsupported Media Type 

my code is below

$file_name_with_full_path = '/home/neosoft/Desktop/VS doc/download.jpeg';

$request_url = 'http://localhost:8090/rest/api/content/7406786/child/attachment';

if (function_exists('curl_file_create')) {
$cFile = curl_file_create($file_name_with_full_path);
} else { //
$cFile = '@' . realpath($file_name_with_full_path);
}

$post = array('id'=>'7406786','comment' => 'abc','file_contents'=>$cFile);

$ch = curl_init();
//curl_setopt($ch, CURLOPT_FILE, $ch);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_USERPWD, "****" . ":" . "****");
curl_setopt($ch, CURLOPT_HEADER, true);
$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$r = curl_exec($ch);
$info = curl_getinfo($ch);
print_r( $info );
curl_close ($ch);


 

 

1 answer

1 accepted

1 vote
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 13, 2018

Hello Vidya,

Looks you have almost everything you need to get your attachment uploaded. It looks like the issue might be related to your headers:

$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/json";

Should Be:

$headers = array();
$headers[] = "X-Atlassian-Token: nocheck";
$headers[] = "Content-Type: multipart/form-data";

Please give that a try, if it doesn’t work please paste the response so we can take a look.

We look forward to your response.

Regards,
Stephen Sifers

Vidya Shevale November 14, 2018 edited

Hello Stephen ,

Thanks for your answer. You are right , I corrected the headers as you said and it's worked .

I added below code

$headers = array();
$headers[] = "X-Atlassian-Token: no-check";

thank you so much

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events