Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curl_setopt($curl, CURLOPT_URL, "https://" . $this->salesforce_host . "/services/oauth2/token");
- curl_setopt($curl, CURLOPT_POSTFIELDS, "client_id=" . $this->salesforce_client_id. "&grant_type=password&client_secret=" . $this->salesforce_client_secret . "&username=" . $this->salesforce_username . "&password=" . $this->salesforce_password . $this->salesforce_token);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded;"));
- // https://$salesforceurl/services/data/v29.0/chatter/feeds/record/$caseId/feed-items
- $session = $this->getSession();
- $url = $session["instanceUrl"] . "/services/data/v" . $this->salesforce_version . "/chatter/feeds/record/" . $parentId . '/feed-items';
- $curl = $this->_getDefaultCurl();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
- //get file mime type and binary content of file
- // form field separator
- $delimiter = uniqid();
- $fileFields = array(
- 'fileFeedItem' => array(
- 'type' => $finfo_mime,
- 'content' => implode('', $buffer)
- ),
- );
- $data = '';
- $data .= "--" . $delimiter . "rn";
- $data .= 'Content-Disposition: form-data; name="json";' . "rn";
- $data .= 'Content-Type: application/json; charset=UTF-8;' . "rnrn";
- $fileName = basename($file);
- $json = array(
- 'body' => array(
- 'messageSegments' => array(
- 'type' => 'Text',
- 'text' => 'User uploaded attachment'
- )
- ),
- 'attachment' => array(
- 'attachmentType' => 'NewFile',
- 'title' => $fileName
- ),
- );
- $data .= json_encode($json)."rn";
- $data .= "rnrn";
- foreach ($fileFields as $name => $fileItem) {
- $data .= "--" . $delimiter . "rn";
- $data .= 'Content-Disposition: form-data; name="feedItemFileUpload"; filename="' .$fileName . '"' . "rn";
- $data .= 'Content-Type: ' . $fileItem['type'] . "rn";
- $data .= 'Content-Transfer-Encoding: binary' . "rn";
- $data .= "rn";
- $data .= $fileItem['content'] . "rn";
- }
- $data .= "--" . $delimiter . "--rn";
- $headers = '';
- $headers .= "Accept: application/xml"."rn";
- $headers .= "Content-Type: multipart/form-data; boundary=".$delimiter."rn";
- $headers .= "Authorization: OAuth ". $session["sessionId"] ."rn";
- $headers .= "Host: ". $session["instanceUrl"] ."rn";
- $headers .= "Content-Length: " . strlen($data) . "rn";
- $headers .= "Expect: 100-continue" . "rn";
- $headers .= "rn";
- $data = $headers . $data;
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- $response_json = curl_exec($curl);
- Accept: application/xml
- Content-Type: multipart/form-data; boundary=52dd7f7e5fd87
- Authorization: OAuth <session_id>
- Host: https://cs30.salesforce.com
- Content-Length: 494
- Expect: 100-continue
- --52dd7f7e5fd87
- Content-Disposition: form-data; name="json";
- Content-Type: application/json; charset=UTF-8;
- {"body":{"messageSegments":{"type":"Text","text":"User uploaded attachment"}},"attachment":{"attachmentType":"NewFile","title":"attachment_test.txt"}}
- --52dd7f7e5fd87
- Content-Disposition: form-data; name="feedItemFileUpload"; filename="attachment_test.txt"
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: binary
- �ttachment_test
- --52dd7f7e5fd87--
- $session = $this->myLogin();
- $url = $session["instanceUrl"] . "/services/data/v" . $this->salesforce_version . "/chatter/feeds/record/" . $parentId . '/feed-items';
- $curl = $this->_getDefaultCurl();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
- $fileName = basename($file);
- $json = array(
- 'body' => array(
- 'messageSegments' => array(
- 'type' => 'Text',
- 'text' => 'User uploaded attachment'
- )
- ),
- 'attachment' => array(
- 'attachmentType' => 'NewFile',
- 'title' => $fileName
- ),
- );
- $headers = array();
- $headers[] = "Authorization: OAuth ". $session["sessionId"];
- $headers[] = "Content-Type: application/json; charset=utf-8";
- $headers[] = "Accept: application/json";
- $fileArray = array(
- 'json' =>$json,
- 'feedItemFileUpload' => '@'.realpath($file),
- );
- $data = json_encode($fileArray);
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLINFO_HEADER_OUT, true);
- $response_json = curl_exec($curl);
- <?php
- $url = "https://na15.salesforce.com/services/data/v29.0/chatter/feeds/record/500i0000004AcIq/feed-items";
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
- $fileName = basename($file);
- $headers = array();
- $headers[] = "Authorization: OAuth {token}";
- $headers[] = 'Content-Type: multipart/form-data; boundary=F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI';
- $segments = array();
- $segments['type'] = 'Text';
- $segments['text'] = 'User uploaded attachment';
- $message = array();
- $message[] = $segments;
- $dataArray = array(
- 'body' => array(
- 'messageSegments' => $message
- ),
- 'attachment' => array(
- 'attachmentType' => 'NewFile',
- 'title' => 'Test File'
- )
- );
- $data = $data.json_encode($dataArray);
- $file = realpath('phoenix-logo.png');
- $post_text = '--F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI
- Content-Disposition: form-data; name="json"
- Content-Type: application/json; charset=UTF-8
- { "body":
- {
- "messageSegments" : [
- {
- "type" : "Text",
- "text" : "Here is another file for review."
- }, {
- "type" : "Hashtag",
- "tag" : "important"
- }, {
- "type" : "Text",
- "text" : "Again, please review this as soon as possible."
- }
- ]
- },
- "attachment":
- {
- "attachmentType" : "NewFile",
- "description": "Phoenix Logo",
- "title" : "Logo.png"
- }
- }
- --F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI
- Content-Disposition: form-data; name="feedItemFileUpload"; filename="logo.png"
- Content-Type: image/png
- '.file_get_contents($file).'
- --F9jBDELnfBLAVmLNbnLIYibT5Icp0h3VJ7mkI--';
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_VERBOSE, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $post_text);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLINFO_HEADER_OUT, true);
- $response_json = curl_exec($curl);
- print $response_json;
- ?>
Add Comment
Please, Sign In to add comment