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
Sonali Rawat 6Sonali Rawat 6 

Hi all, How to display an image in an Aura Component?

Best Answer chosen by Sonali Rawat 6
Arun Kumar 1141Arun Kumar 1141

Hi Sonali,

To display an image in an Aura component using a static resource, you can follow these steps:

1. Upload the image to a Static Resource:
  • Go to Setup in your Salesforce org.
  • In the Quick Find box, search for "Static Resources".
  • Click on "Static Resources" under the "Develop" section.
  • Click on the "New Static Resource" button.
  • Enter a name for the static resource (e.g., "MyImage").
  • Choose the image file from your local system by clicking on "Choose File" or dragging and dropping the file.
  • Click "Save" to upload the image as a static resource.
2. Create an Aura component:
  • Create or open the Aura component file (e.g., MyComponent.cmp).
  • Inside the component markup, add an `<img>` tag to display the image.
  • Set the `src` attribute of the `<img>` tag to the URL of the static resource.
Here's an example of how the Aura component markup would look like:
<aura:component>
    <img src="{!$Resource.MyImage}" alt="My Image" />
</aura:component>

3. Save and deploy the Aura component:
  
Hope this will be Helpful.
Thanks!