Lightning: FileCard Component

The Lightning FileCard component allows users to preview images, documents, and other files whether on desktop or mobile interfaces. It integrates seamlessly with the Lightning app builder and any sObject (Account, Contact, Opportunity etc.) detail page, displaying all uploaded files. It is supported in the Lightning Experience, Salesforce Mobile Web and Lightning Communities.

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 download the files.

This “FileCard” component can be added to the sObject (Account, Contact, Opportunity, etc.) detail page. This component will show all uploaded files with previews on the sObject records. You only need to use lightning app builder to add the component to the record page.

This component displays a preview of the uploaded file, allowing the user to quickly determine which file is being uploaded.

Advertisements

⤵️

Displays a preview of an uploaded file.

Find the component code below:

FilesCardCmp

<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}"/>
</lightning:layoutItem>
</aura:iteration>
</lightning:layout>
</div>
</aura:component>
view raw filesCard hosted with ❤ by GitHub

lightning:fileCard – Attributes

attribute

FilesCardController

({
doInit : function(component, event, helper) {
var action = component.get("c.fetchFiles");
action.setParams({
"linkedRecId" : component.get("v.recordId")
});
action.setCallback(this,function(response){
var state = response.getState();
if(state == "SUCCESS"){
var result = response.getReturnValue()
component.set("v.filesIds",result);
}
});
$A.enqueueAction(action);
}
})

Apex Controller

public class FilesController {
@AuraEnabled
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”.

3

Advertisements
Advertisements
Arun Kumar
Arun Kumar

Arun Kumar is a Salesforce Certified Platform Developer I with over 7+ years of experience working on the Salesforce platform. He specializes in developing custom applications, integrations, and reports to help customers streamline their business processes. Arun is passionate about helping businesses leverage the power of Salesforce to achieve their goals.

Articles: 162

Leave a Reply

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading

Discover more from SFDC Lessons

Subscribe now to keep reading and get access to the full archive.

Continue reading