Lightning: FileCard Component

Displays a preview of an uploaded file.


Lightning FileCard displays a preview of the file. If you use this component on the desktop, and after clicking on files preview it opens the file in the SVG file preview player in lightning experience.  This enables you to preview the image, document and other files in the browser. If you are using this component on mobile and after clicking on the preview downloads the files.

I have implemented this “FileCard” component for the sObject (Account, Contact, Opportunity, etc) detail page. This component will show all the uploaded files (with preview) on the sObject records. You just need to add the component on the record page using lightning app builder.

This component shows the preview of the uploaded file, the user can easily figure out which file is uploaded.

Find the component code below:


<aura:component controller="FilesController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:attribute name="recordId" type="string"/>
<aura:attribute name="filesIds" type="list"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<div class="slds">
<div class="slds-page-header">Uploaded Files</div>
<lightning:layout multipleRows="true">
<aura:iteration items="{!v.filesIds}" var="f">
<lightning:layoutItem padding="around-large" size="6" smallDeviceSize="12" mediumDeviceSize="6">
<lightning:fileCard fileId="{!f.ContentDocumentId}" description="{!f.ContentDocument.title}"/>
view raw filesCard hosted with ❤ by GitHub

lightning:fileCard – Attributes



doInit : function(component, event, helper) {
var action = component.get("c.fetchFiles");
"linkedRecId" : component.get("v.recordId")
var state = response.getState();
if(state == "SUCCESS"){
var result = response.getReturnValue()

Apex Controller

public class FilesController {
public static List<ContentDocumentLink> fetchFiles(String linkedRecId){
List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId,ContentDocument.title FROM ContentDocumentLink WHERE LinkedEntityId =: linkedRecId];
return cdlList;
view raw FilesController hosted with ❤ by GitHub

This files preview player is supported in the “Lightning Experience”, “Salesforce Mobile Web” and “Lightning Communities”.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s