1

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
3
+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.

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.