0

I have a aura file upload component, and it has worked for over a year now. However I have one user where, when she clicks the upload file button, nothing happens (no file browser opens). If she drags a file over the component and drops it, chrome opens a new tab displaying the file, it does not treat it as a file to upload it.

If I log to the community as the same user, everything works like it should, browsing files and uploading.

Since I cannot reproduce the issue myself, I am not sure how to solve, I have searched the internet for hours and no link seems to describe the issue I am seeing.

Any ideas?

Here is the code, not sure why that would help since no code is actually fired since the upload button is internal to the component, but here it is none the less...

cmp

<aura:component implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" controller="Controller_Files" >
<aura:attribute name="accept" type="List" default="['.doc', '.docx', '.pdf', '.jpg', '.jpeg', '.png', '.xls', '.xlsx']"/>
<aura:attribute name="multiple" type="Boolean" default="false"/>
<aura:attribute name="types" type="String[]" default="Encounter Log,Expense Receipt"/>
<aura:attribute name="disabled" type="Boolean" default="false"/>
<aura:attribute name="showBackButton" type="Boolean" default="true"/>
<aura:attribute name="mydata" type="Object"/>
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute name="contactId" type="String" />
<aura:attribute name="timesheetId" type="String" />
<aura:attribute name="url" type="String"/>
<aura:attribute name="pageReference" type="Object"/>

<aura:handler name="init" value="{! this }" action="{! c.init }"></aura:handler>
<lightning:navigation aura:id="navService"/>   
<div class="slds">  
    <aura:if isTrue="{!v.showBackButton}" >
        <div style="padding-bottom: 5px;">
            <lightning:button label="Go Back" variant="brand" onclick="{!c.handleBackClick}"/>
        </div>
    </aura:if>
   <div style="background-color: #bef2c7;
   border: solid 1px rgb(1, 112, 10);
   padding: 5px;">
        <div class="slds-grid">  
            <div class="slds-col slds-size--12-of-12"> 
                <lightning:input type="text" name="input1" label="Enter Document Name" aura:id="fileName" />  
            </div>
        </div>
        <div class="slds-grid"> 
            <div class="slds-col slds-size--12-of-12">  
                <lightning:select name="select" label="Select Document Type" required="true" aura:id="fileDesc">
                    <aura:iteration items="{!v.types}" var="t">
                            <option text="{!t}"></option>
                        </aura:iteration>
                </lightning:select>
            </div>
        </div>
        <div class="slds-grid">  
            <div class="slds-col slds-size--12-of-12">  
                <lightning:fileUpload label="Add document" multiple="{!v.multiple}" 
                                    accept="{!v.accept}" recordId="{!v.timesheetId}" 
                                    disabled="{!v.disabled}"
                                    title="EL File1"
                                    onuploadfinished="{!c.handleUploadFinished}" />
            </div>  
        </div>
    </div>
    <br/>
    <article aura:id="gridContainer" class="slds-card slds-card_boundary">
        <lightning:card title="Documents" iconName="standard:document">
            <div class="slds-card__header slds-grid">
                <aura:if isTrue="{!not(empty(v.mydata))}" >
                    <!-- the container element determine the height of the datatable -->
                    <lightning:datatable keyField="Id"
                            data="{! v.mydata }"
                            columns="{! v.mycolumns }"
                            hideCheckboxColumn="true"
                            sortable="false"
                            onrowaction="{!c.handleRowAction}"></lightning:datatable>
                </aura:if>
                <aura:if isTrue="{!empty(v.mydata)}" >
                    <p>{!v.noResults}</p>
                </aura:if>
            </div>
        </lightning:card>
    </article>

</div>
</aura:component>

controller

({
init: function (component, event, helper) {
    component.set("v.timesheetId",helper.getUrlParameter("timesheetId"));
    component.set("v.showBackButton", helper.getUrlParameter("showBackButton"));
    helper.getGoBackUrl(component);
    helper.getContactId(component);
    helper.fetchData(component);
},

handleUploadFinished : function(component, event, helper) {
   helper.uploadFile(component, event, helper); 
},

handleBackClick: function(cmp, event, helper) {
    window.history.back();
},

handleRowAction: function(component, event, helper) {
    var action = event.getParam('action');
    var row = event.getParam('row');

    switch (action.name) {
        case 'view_file':
            helper.getFile(row);
            break;
    }
}
})

helper

({ 
getContactId: function (cmp) {
    var action = cmp.get('c.getContactId');
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            if(response.getReturnValue() != null) {
                var record = response.getReturnValue();
                cmp.set('v.contactId', record);
            } 
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
        }
    }));
    $A.enqueueAction(action);
},

 fetchData: function (cmp) {
    var action = cmp.get('c.getFiles');
    action.setParams({
        recordId : cmp.get("v.timesheetId")
    });
    action.setCallback(this, $A.getCallback(function (response) {
        var state = response.getState();
        console.log('bw: state = ' + state);
        if (state === "SUCCESS") {
            if(response.getReturnValue() != null) {
                console.log("bw: response = " + response.getReturnValue());
                var actions = [
                    { label: 'View', name: 'view_file' },
                ];
                cmp.set('v.mycolumns', [
                    { label: 'Name', fieldName: 'Title', type: 'text'},
                    { label: 'Type', fieldName: 'Description', type: 'text'},
                    { type: 'action', typeAttributes: { rowActions: actions } }
                ]);
                cmp.set('v.mydata', response.getReturnValue());
            } else {
                cmp.set("v.noResults", "No records to display");
            }
        } else if (state === "ERROR") {
            var errors = response.getError();
            console.error(errors);
            cmp.set("v.noResults", "An error occurred: No records to display");
        }
    }));
    $A.enqueueAction(action);
},

uploadFile: function(component, event, helper) {
    var uploadedFiles = event.getParam("files");
    var documentId = uploadedFiles[0].documentId;
    var fileName = uploadedFiles[0].name;
    helper.updateDocument(component, event, documentId);
    helper.fetchData(component) ;
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
        "title": "Success!",
        "message": "File "+fileName+" Uploaded successfully."
    });
    toastEvent.fire();

    $A.get('e.lightning:openFiles').fire({
        recordIds: [documentId]
    });        
},

updateDocument: function(component, event, Id){
     var action = component.get("c.UpdateFiles");  
     var fName = component.find("fileName").get("v.value"); 
     var desc = component.find("fileDesc").get("v.value");
     //alert('File Name'+fName);  
     action.setParams({"documentId":Id,  
              "title": fName,  
              "description": desc,
              "recordId": component.get("v.timesheetId")  
              });  
     action.setCallback(this,function(response){  
         var state = response.getState();  
         if(state=='SUCCESS'){  
             var result = response.getReturnValue();  
             console.log('Result Returned: ' +result);  
             component.find("fileName").set("v.value", " "); 
             component.find("fileDesc").set("v.value", " ");
             component.set("v.files",result); 
         }  
    });  
    $A.enqueueAction(action);
},

getUrlParameter : function(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
},

getFile: function(row) {
    $A.get('e.lightning:openFiles').fire({
        recordIds: [row.Id]
    }); 
},

getGoBackUrl: function(cmp) {
    var navService = cmp.find("navService");
    // Sets the route to /lightning/o/Account/home
    var pageReference = {
        type: 'comm__namedPage',
        attributes: {
            pageName: 'timesheets'
        }
    };
    cmp.set("v.pageReference", pageReference);
    // Set the URL on the link or use the default if there's an error
    var defaultUrl = "#";
    navService.generateUrl(pageReference)
        .then($A.getCallback(function(url) {
            cmp.set("v.url", url ? url : defaultUrl);
        }), $A.getCallback(function(error) {
            cmp.set("v.url", defaultUrl);
        }));
}
})

Your Answer

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

Browse other questions tagged or ask your own question.