1

I am rendering content document previews in my LWC component by placing <img src> tags into the DOM.

The link i use looks like this:

/sfc/servlet.shepherd/version/renditionDownload/?rendition=THUMB720BY480&versionId={lastVersionId}

The user accesses the page via https://<MyDomain>.lightning.force.com

Unfortunately, it seems that my org responds with a 302 to https://<MyDomain>.my.salesforce.com; and that again responds with a redirect (301 this time) to https://<MyDomain>--c.documentforce.com.

So for each image i render, the browser makes 3 requests. I load images in batches of 50, so the browser makes 151 requests and that is not very performant.

Considering this is a managed package, so i can't just hardcode the URL, is there a way to get the documentforce.com domain in LWC somehow? (or at least in Apex so i can supply it from the backend).

  • what exactly are you using this for ? for preview? or for showing array of images with some details besides them? – salesforce-sas Aug 14 '19 at 8:13
  • both of those, actually. – zaitsman Aug 15 '19 at 0:52
  • Have you tried window.location.origin as per this blog post? – Brian Miller Feb 10 at 21:30
  • @BrianMiller that gives you https://<MyDomain>.lightning.force.com, as my original post says, i need https://<MyDomain>--c.documentforce.com – zaitsman Feb 11 at 23:43
  • I hear, thanks for explaining it out – Brian Miller Feb 12 at 20:40
0

There is no way as of now in LWC. From Apex, you can get the URL like below:

String vUrl = 'https://' + Url.getSalesforceBaseUrl().getHost() + '/sfc/servlet.shepherd/version/renditionDownload.........' ;

You will notice that in this way, there is no documentforce in the URL, but the final URL really works. I can say this because I have worked on a similar kind of scenario a week back.

  • What do you mean by ‘really works’?? The base url gives me the lightning.force.com one – zaitsman Aug 15 '19 at 12:07
  • (Actually, in some orgs i get the https://<MyDomain>.my.salesforce.com which is the second hop, but it's still a hop. I want to get the documentforce.com one) – zaitsman Aug 16 '19 at 3:49

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.