I am trying to upload an attachment using the following function.
public function uploadAttachment($attachmentBody, $attachmentBodyLength, $attachmentName) {
$createFields = array(
'Body' => utf8_encode($attachmentBody),
// 'ContentType' => $contentType,
'Name' => $attachmentName,
'IsPrivate' => 'false',
);
$sObject = new stdclass();
$sObject->fields = $createFields;
$sObject->type = 'Attachment';
$sObject->body = utf8_encode ( $attachmentBody);
echo "Creating Attachment";
$upsertResponse = $this->SFConnection->create(array($sObject));
print_r($upsertResponse);
}
I know that I am not currently specifying a ParentID - this is not my problem
I am getting an error "Caught exception: The element type "Body" must be terminated by the matching end-tag "" when I utf8_encode($attachmentBody).
If I remove the utf8_encode
I get the infamous "Invalid byte 1 of 1-byte UTF-8 sequence." problem!
Where am I going wrong? Has anyone else successfully uploaded attachments through the PHP API?