1

I've used the followed example to upload files in my app:
http://peterknolle.com/file-upload-lightning-component/

At the Helper upload method, I've found the '$A.run' and it's not working anymore, so I took it off. And now, when I select the file to upload at the first time nothing happens, but if I do it again both files are uploaded. Summing up: Code inside 'setCallback' are only executed if upload twice.

    upload: function(component, file, fileContents) {
    var action = component.get("c.saveTheFile"); 

    action.setParams({
        parentId: component.get("v.parentId"),
        fileName: file.name,
        base64Data: encodeURIComponent(fileContents), 
        contentType: file.type
    });

    action.setCallback(this, function(a) {
        attachId = a.getReturnValue();
        console.log(attachId);
    });

    $A.run(function() {
        $A.enqueueAction(action); 
    });
}

Is there any idea to solve my problem?

2

The code you used is out of date now, $A has been deprecated, you now need to use $A.getCallback() instead. I've not dug deeply into this, but pretty sure this'll sort you out:

$A.getCallback(function() {
    $A.enqueueAction(action); 
})();
  • Thank you @MattLacey ... Your solution fixed my problem! – Bruno Perdigão Mar 17 '17 at 14:05

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.