I'm not sure if I am just completely missing something or no one asks this question but I can't find a solution to this. I have a requirement to be able to upload images into the body of a rich text field which is being used to facilitate back and fourth communication in a SFDC community <> console.

enter image description here

I've built a lightning app which works well except I can't figure out how I'm supposed to upload images into the field. Is lightning:inputRichText even capable of doing so? There is no documentation that says it doesn't and it's supposed to replace the legacy ui:richText field (which does not allow for local import anyways). I've also tried the CKEditor approach and that also does not support local import, not to mention with locker service enabled it does not render.

I'm totally stumped, any help is appreciated.

Here is my component in case it helps:

    <aura:component controller="caseCommentsController" implements="force:appHostable,forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global">

  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
  <aura:attribute name="comments" type="Case_Comments__c[]"/>
  <aura:attribute name="newComment" type="Case_Comments__c"
         default="{ 'sobjectType': 'Case_Comments__c'
    <!-- display case comments -->
    <div class="container slds-p-top--medium">
        <div id="list" class="row">
            <aura:iteration items="{!v.comments}" var="comment">
                <c:caseCommentsList comment="{!comment}"/>

    <!-- input form using components -->
    <div class="container slds-p-top--large">
        <form class="slds-form--stacked">
            <div class="slds-form-element">
                <div class="slds-form-element__control">
                    <!-- ui:inputText aura:id="caseid" disabled="true"
                               value="{!v.newComment.Case__c}"/ -->               
         <div class="slds-form-element">
           <div class="slds-form-element__control">
             <lightning:inputRichText aura:id="addComment" 
                                      placeholder="Add a comment..."
          <div class="slds-form-element">
            <ui:button label="Add Comment" 
                       class="slds-button slds-button--neutral"
  </div><!-- ./container-->


3 Answers 3


You can add a file input field in addition to the lightning:inputRichText. Handle file upload with JS controller and add the base64 of the image to a <img> src attribute. Then finally append this <img> element to the end of the lightning:inputRichText value. Doing this the uploaded image will appear at the end of the rich text.

Lightning component:

<lightning:input name="file1" type="file" label="Add image" multiple="false" accept="image/png" onchange="{! c.handleFilesChange }"/>
<lightning:inputRichText value="{!v.richtextvalue}" />

JS controller:

handleFilesChange : function (component, event, helper) {
    var files = event.getSource().get("v.files");
        var file = files[0]
        var reader = new FileReader();
        reader.onload = function () {
            var template = component.get("v.richtextvalue");
            if(template===undefined) template = '';
            template += '<img src="'+reader.result+'"/>';
        reader.onerror = function (error) {
            console.log('Error: ', error);

Note that when saving this richtextvalue to a richtext field on an object, sf will take your base64 src and convert it to a url pointing to the image which they saved to documentforce.com This url is sadly not publicly accessible and will return a 404 when used outside your salesforce org. So thread carefully.


Did you try copying and pasting the image? I am in similar scenario - the image is pasted Ok, but the lightning page renders just with the link of the image instead of actually showing the image. I don't think the attach option to upload image is not available on lightning:inputRichtext yet.


Have a look at the code below

<lightning:inputRichText variant="bottom-toolbar" value="{!v.myVal}" placeholder="Type something interesting">

This should give the upload image within the rich text

  • It doesn't work.
    – gvgramazio
    Commented Jun 27, 2019 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .