Forums

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

How to send attachment in confluence

Vidya Shevale October 21, 2018

I am trying to send attachment using php curl

and I am using postman for it

i am sending raw data

{
    "id":3244039,
    "comment":"attachment",
    "file":"@/home/neosoft/Pictures/Screenshot from 2018-10-04 16-23-33.png"
}

 

an my  php  api code is below

$qbody = file_get_contents("php://input");
        $json = json_decode(file_get_contents("php://input"));
        $CURLOPT_URL = "http://localhost:8090/rest/api/content/".$json->id."/child/attachment";
           $ch         = curl_init();
        curl_setopt($ch, CURLOPT_URL, $CURLOPT_URL);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,  $qbody);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_USERPWD, "admin" . ":" . "Abc@1234");
        //$headers = array();
        //$headers[] = "Content-Type: application/json";
        //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/binary'));
        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close ($ch);
        print_r($result);

 

but I am getting error

<html>
    <head>
        <title>Apache Tomcat/8.0.43 - Error report</title>
        <style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
    </head>
    <body>
        <h1>HTTP Status 415 - Unsupported Media Type</h1>
        <div class="line"></div>
        <p>
            <b>type</b> Status report
        </p>
        <p>
            <b>message</b>
            <u>Unsupported Media Type</u>
        </p>
        <p>
            <b>description</b>
            <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</u>
        </p>
        <hr class="line">
        <h3>Apache Tomcat/8.0.43</h3>
    </body>
</html>

 

please help me TIA

 

 

 

1 answer

0 votes
Gonchik Tsymzhitov
Community Champion
October 23, 2018

Hi! 

 

Looks like you forgot a few parameters like this:

data = { 'type': type, "fileName": filename, "contentType": content_type, "comment": comment, "minorEdit": "true"} headers = { 'X-Atlassian-Token': 'nocheck', 'Accept': 'application/json'}

 

Please, have a look this solution

https://github.com/atlassian-api/atlassian-python-api/blob/master/atlassian/confluence.py#L291

 

Cheers,

Gonchik Tsymzhitov

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events