Skip to content
Salesforce Factory
Salesforce Factory

Salesforce Factory

A Complete Blog on Salesforce and Beyond

  • Home
  • Authors
  • Contact

Tag: Upload Logo

Posted on November 12, 2018

Upload Logo from Lightning Component

  • tweet 
  • share 
  • share 

From a lightning component, If you would like to Upload a Logo/Attachments/Images into an object of Salesforce
this post would be really helpful.

After a long work around I was able to figure out how to upload attachments from outside.

Using the below code, you can directly attach the file and upload into object.

Component Code:

<lightning:layoutItem padding=”around-small” size=”4″>
<lightning:input aura:id=”file-input1″ type=”file”
files=”{!v.fileToBeUploaded2}”
accept=”image/png, image/jpeg”
onchange=”{!c.onFileSelected2}”
label=”Logo 2″
name=”file1″ multiple=”false”/>
<div>
File Selected: {!v.uploads.fileToBeUploaded2Name}
</div>
</lightning:layoutItem>

Controller

onFileSelected1:function(component,event,helper){
let files = component.get(“v.fileToBeUploaded1”);
if (files && files.length > 0) {
let file = files[0][0];
let uploads = component.get(“v.uploads”);
uploads[“fileToBeUploaded1Name”] = file.name;
component.set(“v.uploads”,uploads);
}

Helper

let uploads = component.get(“v.uploads”);
uploads.success = [];
component.set(“v.uploads”,uploads);

There is also a standard lightning design system tag that can be used in the lightning component.But, the limitation is that
It can only be used internally. If you would like to upload images from public facing forms we can use the custom code i have given.

File Upload

Component

<aura:component>
<aura:attribute name=”accept” type=”List” default=”[‘.jpg’, ‘.jpeg’]”/>
<aura:attribute name=”multiple” type=”Boolean” default=”true”/>
<aura:attribute name=”disabled” type=”Boolean” default=”false”/>

<lightning:fileUpload name=”fileUploader”
label= “Demo Upload”
multiple=”{!v.multiple}”
accept=”{!v.accept}”
disabled=”{!v.disabled}”
recordId=”abcd”
onuploadfinished=”{! c.handleUploadFinished }”/>

</aura:component>

Controller

({
handleUploadFinished: function (cmp, event) {
// This will contain the List of File uploaded data and status
var uploadedFiles = event.getParam(“files”);
alert(“Files uploaded : ” + uploadedFiles.length);
}
})

–Chandra V[11/11/18]

  • tweet 
  • share 
  • share 

Enter Keywords

Categories

  • Admin Posts (7)
  • Developer Posts (20)
  • Discussions (1)
  • Lightning Communities (1)
  • Salesforce CMS (1)

Archives

  • June 2021 (1)
  • March 2021 (2)
  • January 2021 (1)
  • September 2020 (1)
  • August 2020 (1)
  • June 2020 (3)
  • September 2019 (1)
  • August 2019 (1)
  • July 2019 (1)
  • March 2019 (4)
  • February 2019 (1)
  • January 2019 (2)
  • November 2018 (2)
  • October 2018 (9)

Recent Posts

  • Salesforce Summer’21 release Highlights / Development / Administration June 7, 2021
  • Deleting Apex Classes / Apex Triggers from Production using Workbench March 2, 2021
  • Salesforce CMS March 2, 2021
  • Salesforce Spring ’21 Highlights / KeyPoints / Non-Lightning January 12, 2021
  • Salesforce Winter ’21 release notes – Highlights September 10, 2020

Advertisement

Advertisement

About This Site

Saleforce Factory

A Complete Blog on Salesforce and Beyond

Site Statistics

  • Visitors today : 0
  • Total visitors : 71,324
Proudly powered by WordPress