8 answers
@SumitKumar10
For LWC I didn't get any solution but for Aura component you can show preview on community.For You can refer below code:Component Code:
<aura:iteration items="{!v.SignedGADPackage}" var="item" indexVar="index">
<tr><td width="25%">{!item.docName}</td><td width="25%"><lightning:formattedDateTime value="{!item.generatedDocTime}" year="numeric"month="numeric" day="numeric" hour="2-digit" minute="2-digit"hour12="true" /></td><td width="25%">{!item.generatedBy}</td><td width="25%"><a href="" id="{!item.conDocId}" onclick="{!c.previewFile}">View <lightning:icon size="x-small" iconName="action:preview" alternativeText="Preview"title="Preview" /></a> <a href="javascript:void(0)" id="{!item.conDocId}"onclick="{!c.downloadFiles}">Download <lightning:icon size="x-small" iconName="action:download" alternativeText="Download"title="Download" /></a></td></tr></aura:iteration>
JS Code:
previewFile: function (component, event, helper) {var rec_id = event.currentTarget.id;$A.get('e.lightning:openFiles').fire({recordIds: [rec_id]});},downloadFiles : function (component, event, helper){var documentId = event.currentTarget.id;var urlString = window.location.href;var baseURL = urlString.substring(0, urlString.indexOf("/s"));var urlEvent = $A.get("e.force:navigateToURL");urlEvent.setParams({"url": baseURL + '/sfc/servlet.shepherd/document/download/' + documentId + '?operationContext=S1'});urlEvent.fire();},Please markit as best answer if this helps you.Thanks,Arpit