function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bhuvana dasbhuvana das 

How to download the attachments of the record in lightning component?

How to download the "Attachements" which are queried and displaying on custom component. or is there any lightning component for download the attachments (we don't want to use standard things) in napili community template.
NagendraNagendra (Salesforce Developers) 
Hi Bhuvana,

On your apex server side code you need to select the attachment object -> all the attachments of the selected objects ids.

Create a wrapper apex class that will represent 1 record with a list of attachments and prepare your data so each record has a list of attachments. Then send a list of this wrapper class back to the client (you can do this also on the client side javascript and not from the server).

on your client side markup you should define an attribute from the wrapper class, and have an aura:iteration for each record, and inside another aura:iteration for the attachments in each record:
<aura:attribute type="ControllerClass.wrapperClass[]" name="records" />
Displaying the downloadable links - you can do in many ways - for example, I display download links like that (where att is the iteration variable):
<div class="slds-media__body"> <h3 class="slds-truncate" title="File Name"> <a href="{!'/servlet/servlet.FileDownload?file='+att.Id}">{!att.Name}</a> </h3> <div class="slds-tile__detail slds-text-body--small"> <ul class="slds-list--horizontal slds-has-dividers--right"> <li class="slds-item"> <ui:outputDate format="dd/MM/yyyy HH:mm" value="{!att.LastModifiedDate}"/> </li> <li class="slds-item"> KB&nbsp;<ui:outputNumber format="#,###,###.#" value="{!(att.BodyLength) / 1000}" /> </li> </ul> </div> </div>
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra