1

I'm trying to display an image related to one of my objects. When querying through API I get this: <img src="/servlet/servlet.FileDownload?file=<some_image_id>" alt="No doc linked" height="800" width="800" border="0"/>

Now, when I'm logged in to SalesForce I can view the image from my browser using that url. But, without loggin-in I can't.

I've searched through the documentation but I couldn't find my legs and hands, it's very unclear to my taste.

My question is - what do I need to do to be able to display an image on an external site (using auth token or what have you - I just can't find the correct way)?

2

Are you using rest or soap? Rest, you can use the oAuth response headers to get the instance URL.

Example of the rest headers returned with the access token

{
    "id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
    "issued_at":"1296458209517",
    "scope": "id full api openid refresh_token chatter_api",
    "instance_url":"https://na1.salesforce.com",
    "token_type": "Bearer",
    "refresh_token":"5Aep862eWO5D.7wJBuW5aaARbbxQ8hssCnY1dw3qi59o1du7ob.lp23ba_3jMRnbFNT5R8X2GUKNA==",
    "id_token": "eyJhb...h97hc",
    "signature":"0/1Ldval/TIPf2tTgTKUAxRy44VwEJ7ffsFLMWFcNoA=",
    "access_token":"00D50000000IZ3Z!AQ0AQDpEDKYsn7ioKug2aSmgCjgrPjG9eRLza8jXWoW7uA90V39rvQaIy1FGxjFHN1ZtusBGljncdEi8eRiuit1QdQ1Z2KSV"
}

Then you can append the instance_url to the relative URLs received in your call.

If soap, you can use the endpoint in the session object to grab the endpoint IIRC

|improve this answer|||||
  • thanks for the fast reply! given I have my client access key and secret how do I get the token or refresh it? is there a documentation you can point me to? – wilfo Dec 26 '16 at 16:53
  • Best resource out there is here: - developer.salesforce.com/page/… - For a complete example of implementing oauth using Apex/VF as an example look here - salesforce.stackexchange.com/questions/85664/… - – Eric Dec 26 '16 at 16:56
  • another question - in the flow you described, where would I put the token I have in the image url? – wilfo Dec 27 '16 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.