6

As I understand, the multiple attribute, when set to false, will limit the number of files uploaded at a time to 1:

Specifies whether a user can upload more than one file simultanesouly. This value defaults to false.

Reference here.

However, even if I explicitly set this value to false, I am still able to select multiple files to upload at a time, either via the document selector window, or the drag-and-drop:

Code snippet:

<lightning:fileUpload 
    label="Attach receipt"
    multiple="false" 
    accept=".pdf, .PDF, .png, .PNG, .jpg, .JPG"
    recordId="{!v.recordId} " 
    onuploadfinished="{! c.handleUploadFinished }" />

Screenshot of my simultaneous upload issue:

enter image description here

API Version

  • 41

Should I do this check in ContentDocument trigger? However I don't want to even reach the backend. I wanted to deal with all these conditions in the frontend.

  • 2
    That looks like a bug to me .Have you filed a case with support ? – Mohith Shrivastava Feb 1 '18 at 2:22
4

After hours of pain, I found a workaround.

Before this workaround, the lightning fileupload component creates an html like this:

<input type="file" id="input-1" aria-labelledby="input-1-form-label input-1-file-body-label" accept=".pdf, .jpg" multiple="" class="slds-file-selector__input slds-assistive-text">

After the workaround was implemented, the multiple="" disappeared.

The workaround is to explicitly set the multiple attribute to false in the controller.

The fileupload will look something like this (the important thing in this one is the aura:id, which will be used later):

<lightning:fileUpload 
    label="Attach receipt"
    multiple="false" 
    accept=".pdf, .jpg"
    recordId="{!v.recordId}" 
    onuploadfinished="{! c.handleUploadFinished }" 
    aura:id="lightningFileUpload" />

In the component, I added a handler to the render event:

<aura:handler name="render" value="{!this}" action="{!c.onRender}"/>

Once the render event finishes, I call the fileupload component, and set its multiple attribute to false:

onRender : function(component, event, helper) {
  component.find("lightningFileUpload").set("v.multiple", false);
}

It's the nearest workaround I can find that doesn't involve hacking my way via css, vanillaJS, or even catching stuff in the ContentDocument trigger.

  • Woooo .That never struck to me .Thats great working around the problem .+1 from me – Mohith Shrivastava Feb 1 '18 at 14:26
4

This looks like a bug to me for sure .The component outputs a HTML tag as below for the code

<lightning:fileUpload label="Attach receipt"
    name="fileUploader"
    accept=".pdf,.png"
    recordId="{!v.recordId}" 
    onuploadfinished="{!c.handleUploadFinished}" />

This is output as below . Notice multiple attribute in the input html tag .

<input type="file" id="input-1" aria-labelledby="input-1-form-label input-1-file-body-label" accept=".pdf,.png" multiple="" name="fileUploader" class="slds-file-selector__input slds-assistive-text">

There is not lot you could do than server validation as the hooks before file upload is not exposed to you as the developer .So report as a bug to SFDC .

Update

Sounds like SFDC has a fix .The below code is believed to work

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" > 
  <aura:attribute name="myRecordId" type="String" description="Record to which the files should be attached" /> 
  <aura:attribute name="multiple" type="Boolean" default="false" /> 
     <lightning:fileUpload label="Attach receipt." 
   multiple="{!v.multiple}" 
  accept=".pdf, .png" 
  recordId="xxxxxxxxxxxxxxx" 
  onuploadfinished="{!c.handleUploadFinished}" 
   aura:id="lightningfileUpload"/> 
</aura:component> 

The controller code

({ 
    handleUploadFinished: function (cmp, event) { 
//  Get the list of uploaded files 
    var uploadedFiles = event.getParam("files"); 
    alert("Files uploaded : " + uploadedFiles.length); 
   } 

}) 
  • 2
    No you need a PROD to do that .I can raise it on your behalf tomorrow and share details if you do not have access – Mohith Shrivastava Feb 1 '18 at 3:21
  • 1
    I would appreciate it if you can report it on my behalf. Thank you very much. – SamuelDev Feb 1 '18 at 3:22
  • 1
    Case opened for this one .The case no is 18239480 – Mohith Shrivastava Feb 1 '18 at 3:40
  • 1
    Hi Mohith. I found a workaround, I posted it below. Hopefully the lightning team can fix this for the next release. – SamuelDev Feb 1 '18 at 14:23
  • 1
    Heard from support that this issue will be fixed and rolled out in all the orgs and sandboxes in coming days . – Mohith Shrivastava Feb 8 '18 at 17:20

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.