2

I am Uploading the Image from LWC page by using lightning-file-upload and Making the Image as Public accessible as Below

ContentVersion cv = [select id from contentversion where contentdocumentid =:documentId];
ContentDistribution cd = new ContentDistribution();
cd.Name = 'Test';
cd.ContentVersionId = cv.id;
cd.PreferencesAllowViewInBrowser= true;
cd.PreferencesLinkLatestVersion=true;
cd.PreferencesNotifyOnVisit=false;
cd.PreferencesPasswordRequired=false;
cd.PreferencesAllowOriginalDownload= true;
insert cd;
SELECT DistributionPublicUrl FROM ContentDistribution WHERE ContentDocumentId

Sample URL: https://psas--sandboxone.my.salesforce.com/sfc/p/6w0000008jRU/a/6w000000Gn7s/Lic0.Hgi5VwyYli3xJcMMjJs6mauT7fSWxUCTROTjyc

If I use the above URL in HTML img tag, Image is not showing, Can anyone Please help me solve this issue

<div class="slds-align_absolute-center">
                                       <img style="-ms-interpolation-mode:bicubic;border:none;max-width:100%;outline:none;width: 250px;vertical-align: bottom;"
                                           width="32"
                                           src="https://psas--sandboxone.my.salesforce.com/sfc/p/6w0000008jRU/a/6w000000Gn7s/Lic0.Hgi5VwyYli3xJcMMjJs6mauT7fSWxUCTROTjyc"> 
                                       
                                   </div>
4
  • That URL is likely for the page that will load the image not the image itself. The image url in you case is psas--sandboxone--c.documentforce.com/sfc/dist/version/…
    – manjit5190
    Commented Oct 21, 2020 at 15:24
  • @manjit5190 how you frame this URL. Commented Oct 21, 2020 at 16:41
  • Can you Please help me to Understand on this? Commented Oct 21, 2020 at 16:44
  • I am not really sure how can we generate that. I'll wait for someone who has worked on it to provide an answer.
    – manjit5190
    Commented Oct 22, 2020 at 8:37

1 Answer 1

4
+50

Instead of DistributionPublicUrl Use ContentDownloadUrl

SELECT ContentDownloadUrl FROM ContentDistribution WHERE ContentDocumentId

You must get the ContentDownloadURL in the Image Source of the Site that you want to use.

1
  • Works as a charm I tried many hours using DistributionPublicUrl this showed the image from direct URL but not in LWC. And your solution of using ContentDownloadUrl saved my day! Commented Apr 22 at 5:43

You must log in to answer this question.

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