function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Joseph MurawskiJoseph Murawski 

recordId not being refreshed in Lightning component helper method

I have a custom lightning component that uses:  
<input type="file" class="slds-file-selector__input slds-assistive-text" 
                                   onchange="{!c.saveFile}" aura:id="file"
                                   accept="image/png;image/jpg;image/gif" id="file-upload-input-01" 
                                   aria-labelledby="file-selector-primary-label file-selector-secondary-label" />
to upload a file (Attaching code for saveFile function).
My problem is that when I use the component on account record and then switch to another record, when I process the upload on the other record it still uses the account record ID in the save routine.  I have checked to make sure the component recordId from the hasRecordId is loading correctly.  
 
ComponentController:
    saveFile: function(component,event,helper) {
        helper.showSpinner(component,"spinner");
		helper.uploadMe(component,event,helper);  
    },

Helper:
    upload: function(component, file, base64Data, helper,event) {  
        var action = component.get("c.saveAttachment"); 
        action.setParams({
            parentId: component.get("v.recordId"),
            fileName: file.name,
            base64Data: base64Data, 
            contentType: file.type
        });
        console.log("c.saveAttachment time start: " + Date.now())
        action.setCallback(this, function(a) {
        console.log("c.saveAttachment time callback returned: " + Date.now())
            var state = a.getState();
            if (state === "SUCCESS") {
		        console.log("c.saveAttachment time callback success: " + Date.now())
                helper.hideSpinner(component,"spinner");
                component.set("v.message", "");
                component.set('v.deleteIconClass', 'slds-float--right slds-p-right_small');
                helper.ToastMe(component, event, helper, "success", "Image uploaded");
                $A.get('e.force:refreshView').fire();
            }
            else {
                component.set("v.message", "");
                helper.ToastMe(component, event, helper, "error", "Image Upload Failed");
            }
        });
        console.log("c.saveAttachment time callback queued: " + Date.now())
        $A.enqueueAction(action); 
    },
    uploadMe: function(component,event,helper)
    {
        var fileInput = component.find("file").getElement();
    	var file = fileInput.files[0];
        var fSize = 0;

        if (!file) return;

        if (!file.type.match(/(image.*)/)) {
            helper.ToastMe(component, event, helper, "error", "Image file not supported");
  			return;
		}
        if (file.size > this.MAX_FILE_SIZE_SM) {
			fSize = 1;
            helper.ToastMe(component, event, helper, "error", "File needs to be less than 1024 KB.  Current size: " + file.size);
            return;
            
        }
        
        var self = this;
        var fr = new FileReader();
        fr.onloadend = function() {
            var dataURL = fr.result;
            component.set("v.pictureSrc", dataURL);
            helper.upload(component, file, dataURL.match(/,(.*)$/)[1],helper,event);
            
        };
        fr.readAsDataURL(file);
    },

 
Best Answer chosen by Joseph Murawski
Joseph MurawskiJoseph Murawski
I did not find THE answer, but I implemented lightning:Input type="File" instead of Input type="File" and it seems to have fixed the issue.