2

Does anyone have an idea about uploading a new version of a File in Lightning Component using the base lightning component lightning:fileUpload?

I tried passing ContentDocumentId into recordId parameter, but it returns error on upload.

<lightning:fileUpload  name="fileUploader"
                           label= "Demo Upload"
                           multiple="true"
                           recordId="{!v.recordId}" />
8
  • please share your component code including apex controller if applicable, thanks
    – glls
    Commented Apr 16, 2018 at 21:50
  • component code was just one line, I've added to my question now.
    – VarunC
    Commented Apr 17, 2018 at 6:54
  • What about your apex controller, this component won’t update/replace existing files on its own
    – glls
    Commented Apr 17, 2018 at 12:39
  • I didn't had any APEX Controller. The only hook I see in docs is onuploadfinished, that happens after we upload document. What else can we do in APEX regarding this component?
    – VarunC
    Commented Apr 17, 2018 at 12:42
  • You want to replace/update the existing attached document? So you would manage that part of the logic in your apex controller
    – glls
    Commented Apr 17, 2018 at 12:50

1 Answer 1

2

This cannot be done with the lightning:fileUpload component.

I solved this problem with the lightning:openFiles event.

This way a user has a preview of the file and inside the previewer you can upload a new version, delete, download and so on:

enter image description here

Here is some code sample:

Markup

<aura:attribute name="file" type="ContentDocumentLink" description="content file - taken from server" />

<div onclick="{!c.previewFile}" id="{!file.ContentDocumentId}">
    <lightning:tile label="{!file.fileName}" title="Click to preview and manage uploaded file">
        <aura:set attribute="media">
            <lightning:icon iconName="doctype:unknown" size="xx-small"/>
        </aura:set>
    </lightning:tile>
</div>

Controller

previewFile: function(component, event, helper) {
    var contentId = event.currentTarget.id;
    $A.get('e.lightning:openFiles').fire({
        recordIds: [contentId]
    });
},

You must log in to answer this question.

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