Salesforce Rendition + Microsoft Cognitive API = Happy Customers - Part 2

Yesterday I blogged about the idea of including microsoft's cognitive api to analyze image getting generated from Salesforce content rendition at

However yesterday I was facing challenge in connecting the Salesforce file preview image to cognitive apis.

The major challenge was that Salesforce was not allowing me to get an insecure http image url for the preview renditions. Because of this I was not sure how the image url will be scanned by the cognitive apis.

But wait! there was another way to provide the content

Supported input methods: Raw image binary in the form of an application/octet stream or image URL.

The documentation said it can take raw image binary. This was a life saver for me as the rendition apis in Salesforce was capable of giving an InputStream for the generated thumbnail.

Now the only gap that need to be bridged was to convert this InputStream to InputStreamEntity and send it to the cognitive apis. Wallah! it worked seamlessly. :)

Here is the node.js client call that has been added after making the changes 

  1. Upload a File in Chatter feed
    response = crmtest.insertChatterFeedFile("/Users/Documents/pdf.pdf", "File Name","Title", accessToken);
    var fileId = crmtest.parseresponse(response,"id");
    • In order to upload a file in chatter insertchatterfeedwithfile method is invoked
    • First parameter is the file location
    • Second parameter will be the file name
    • Third will be the file title
    • Fourth will be the oauth accesstoken
    • Once the response is recieved it can be parsed through and corresponding file id of the uploaded file can be retrieved.
  2. Send the generated thumbnail preview from file rendition to Microsoft's cognitive api and get image analytics
    response = crmtest.analyzeimage(fileId, "<<Microsoft cognitive api key>>", accessToken);
    • Once file preview are generated, in order to get more analytics out of that send the fileId to the analyzeimage call with the Microsoft's cognitive api and accessToken
    • Raw Image is read from the chatter api and passed to the Microsoft's cognitive api. Note: Microsoft is not going to store the images as per its documentation
Execution time 
I uploaded the below seminar pic in my chatter feed 

Here is the output

-----------Analyze the generated file preview----------------
{"tags":[{"name":"indoor","confidence":0.98557054996490479},{"name":"auditorium","confidence":0.23898179829120636}],"description":{"tags":["indoor","room","large","building","sitting","table","auditorium","computer","people","man","group","laptop","crowd","standing"],"captions":[{"text":"a crowd of people in a room","confidence":0.26782138202681804}]},"requestId":"a23ecf3e-c0da-42b2-8d48-367848a97b93"} 

Note tags are nothing but the suggested topics in salesforce terms.

For more details refer to which is updated with these changes. In order to contribute towards crmtest refer at

Hope this will help you in getting more out of Salesforce content.


Post a Comment

Popular posts from this blog

Firebase authentication with Ionic creator

Big Data - SWOT Analysis

LINKEDIN api call using NODE.JS OAUTH module