0

I am trying to pop open a modal form with an input to upload a documentation image on it. Everything else on the form is working perfectly fine, I just had a last minute ask to add this file input functionality and have the uploaded file land in the Notes & Attachments object, is this possible? I suggested adding a field on the current object I'm uploading things to from this form to capture the upload, which is what I have a feeling I'm going to end up having to do. Here is my code. It's messy because it's late and I would like to know if this is possible before I continue on any more tonight. I'm working on a Lightning Community in a Spring '18 sandbox.

<div class="slds-form-element">
            <span class="slds-form-element__label" id="file-selector-id">File Attachment:</span>
            <div class="slds-form-element__control">
                <div class="slds-file-selector slds-file-selector_files">
                    <div class="slds-file-selector__dropzone">
                        <input type="file" class="slds-file-selector__input slds-assistive-text" accept=".png, .jpg" id="file-upload-input-01" aria-describedby="file-selector-id" aura:id="file" onchange="{!c.showfile}"/>
                        <label class="slds-file-selector__body" for="file-upload-input-01">
                            <span class="slds-file-selector__button slds-button slds-button_neutral">
                                <lightning:icon iconName="utility:download" size="x-small"/>
                                Upload Files
                            </span>
                            <span class="slds-file-selector__text slds-medium-show">or Drop Files</span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
  • In my understanding, you want to upload a image as an attachment to a record.right? – A.Bretto Jan 24 '18 at 5:39
  • Yes that is correct. – KF. Jan 24 '18 at 5:42
1

You need to read the image with File Reader and convert it as base64 String and pass it to the Server controller where you have to do the DML in Attachment Object. Please refer File upload as Attachement.

Hope this helps.

0

Awesome thanks for the responses guys. I wound up having to remove the force:recordData sections of my cmp (I have had mixed results in Communities with it) and set everything I needed to set on the apex controller (it's complicated). Once I did that my lightning:fileUpload enabled itself and worked like a charm! Thanks so much again, I am new at using this site but so far everybody has been very helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.