Hello All,
I have trying for quite awhile to post a file as an attachment using the rest api with php curl. I have seen similar questions out there, and I tried to emulate those who said they had success, but it just does not seem to work for me. I would greatly appreciate and welcome any suggestions.
My code:
$ch = curl_init();
$file = 'C:\path\path\path\path.txt';
if (function_exists('curl_file_create')) {
$cFile = curl_file_create($file);
} else {
$cFile = '@' . realpath($file);
}
$postData = array('file_contents' => $cFile);
$headers = array();
$headers[] = "X-Atlassian-Token: no-check";
curl_setopt($ch, CURLOPT_URL, "http://localhost:8090/rest/api/content/31391748/child/attachment");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "****" . ":" . "****");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
print_r($info);
curl_close ($ch);
I noticed I am getting a HTTP code of 400 when $info prints, which I know means it is a bad request. I am not sure what could potentially be causing this. Again, any help will be much appreciated!