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);
Community moderators have prevented the ability to post new answers.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.