0

Using a webservice we are retrieving data and displaying it in our SalesForce Environment using lightning components. This webservice is password protected and we are passing the credentials along with our webservice requests.

This webservice can also serve images, but these are also password protected, so I can not add this URL in an <img src="" /> tag. I have now solved it by making an httpconnection and base64 encoding the result data. Then let aura place the value in the src attr. <img src="{! 'data:image;base64,'+data }" />

Is this the best way of solving this or would there be another recommended SalesForce way of doing this?

2
  • How images are password protected in webservice response?
    – Saroj Bera
    Commented Feb 17, 2017 at 10:36
  • The request will return a 401 status code if an unauthenticated user requests the image. I solved it by base64 endcoding the image and returning it as a var which then is placed in the src attr of the img tag. Is this a proper way of doing this?
    – Stijn
    Commented Feb 17, 2017 at 15:23

1 Answer 1

0

To solve this issue I have done the following, download the image using apex with an httpconnection and base64 encoding the result data and add the String data:image;base64,. Then let aura place the value in the src attr. <img src="{! data }" />

Then start a job to store the downloaded image as an attachment in the Salesforce database. The next time the image is requested, it can serve the image using the following URL: /servlet/servlet.FileDownload?file=<some_image_id>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .