0

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}" />
  • please share your component code including apex controller if applicable, thanks – glls Apr 16 '18 at 21:50
  • component code was just one line, I've added to my question now. – VarunC Apr 17 '18 at 6:54
  • What about your apex controller, this component won’t update/replace existing files on its own – glls Apr 17 '18 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 Apr 17 '18 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 Apr 17 '18 at 12:50
1

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]
    });
},

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.