I found the problem contrary to what the documentation stipulates you should populate the document when creating it. You should add your bytes array to the Document's Content field.
Here's the code:
$file = 'Eurocopter-EC130.jpg';
$handle = fopen($file, "rb");
$fsize = filesize($file);
$contents = fread($handle, $fsize);
$byteArray = unpack("N*",$contents);
$uploadArray = array(
'Name' => $file,
'FileType' => 'Image',
'StorageType' => 'File',
'Content' => $byteArray
);
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, URLCLARIZEN_DATAOBJECTS . '/' . DOCUMENT);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch1, CURLOPT_HTTPHEADER, $_SESSION['currentUser']->getAuthenticationHeader());
curl_setopt($ch1, CURLOPT_POSTFIELDS, json_encode($uploadArray));
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
$documentResultArray = json_decode(curl_exec($ch1), TRUE);
// Create attachment link
$uploadArray = array(
'Entity' => $caseResultArray['id'],
'Document' => $documentResultArray['id'],
);
$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, URLCLARIZEN_DATAOBJECTS . '/' . ATTACHMENT_LINK);
curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch1, CURLOPT_HTTPHEADER, $_SESSION['currentUser']->getAuthenticationHeader());
curl_setopt($ch1, CURLOPT_POSTFIELDS, json_encode($uploadArray));
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
$attachmentLinkResultArray = json_decode(curl_exec($ch1), TRUE);