I have a custom module which uses Salesforce class to get binary data (files) from Salesforce Attachments with objectRead() method. However, currently salesforce.inc assumes that all response is JSON-decodeable, which then breaks $response->data if it included BLOB data instead of JSON. See Salesforce documentation for getting blob data from an object.

Todo: Check if this breaks salesforce_soap. Has been tested only with Salesforce REST api.

Comments

juhaniemi’s picture

juhaniemi’s picture

Issue summary: View changes
juhaniemi’s picture

Status: Active » Needs review
dbcollies’s picture

The patch looks good to me, with one very minor exception: it breaks Drupal coding standards (and throws a warning when applying it) because it adds a line with only blank spaces. But, functionally it works well, as far as I can see.

I tested only using REST, not SOAP.

dbcollies’s picture

Sorry - entered my comment on the wrong issue. :(

KeithC’s picture

I've also experienced this issue with getting file data when trying to use the Salesforce module within my own custom module.

However, I've made a patch that I feel is a bit tidier.

My apologies if I've done anything incorrectly. This is my first patch!

Thanks

KeithC’s picture

We've just noticed that both of the original patches cause a warning to be thrown when $this->response->headers['content-type'] is not set, for example when doing $data = $this->apiCall("sobjects/{$name}/{$key}/{$value}", $params, 'PATCH');.

I've uploaded a new patch which checks it's set before trying to use it.

Thanks

aaronbauman’s picture

Checking response headers is probably a good idea anyway.
I think an switch statement is probably a cleaner implementation.

Is 'application/octet-stream' the content-type in the response header?
Something else we should look out for?

e.g.

diff --git a/includes/salesforce.inc b/includes/salesforce.inc
index d92f72a..f830a81 100644
--- a/includes/salesforce.inc
+++ b/includes/salesforce.inc
@@ -121,6 +121,8 @@ class Salesforce {
         }
     }
 
+    switch ($this->response->headers['content-type']) {
+      case 'application/json':
     $data = drupal_json_decode($this->response->data);
     if (!empty($data[0]) && count($data) == 1) {
       $data = $data[0];
@@ -135,6 +137,13 @@ class Salesforce {
     }
 
     return $data;
+
+      case 'application/octet-stream':
+        return $this->response->data;
+
+      default:
+        throw new SalesforceException(t('Unknown response type "@type"', array('@type' => $this->response->headers['content-type']));
+    }
   }
 
   /**

aaronbauman’s picture

Status: Needs review » Needs work

NW per previous comment.

aaronbauman’s picture

Component: Code » salesforce.module
Status: Needs work » Closed (won't fix)

7.x is no longer supported

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.