I'm testing a component where I upload a file, convert to base64 and split into several CHUNK Parts send each one to an apex method.

This component seems quite common online. Like:

Bellow, is the method that performs my invocation to apex

uploadInChunk: function(component, file, fileContents, startPosition, endPosition, actualPart, totalParts) {

    var filePart= fileContents.substring(startPosition, endPosition);

    var action = component.get("c.uploadDocument");
       actualPart: String(actualPart),
       totalParts : String(totalParts),
       recordID : component.get('v.recordID'),
       part : filePart

    action.setCallback(this, function(response) {

        var state = response.getState();
        if (state === "SUCCESS") {
                startPosition = endPosition;
                endPosition = Math.min(fileContents.length, startPosition + this.CHUNK_SIZE);
                if (startPosition < endPosition) {
                    this.uploadInChunk(component, file, fileContents, startPosition,endPosition,(actualPart+1),totalParts);
                } else {
                    this.showToast(component,$A.get("$Label.c.uploading"), 'Info');
         } else if (state === "INCOMPLETE") {
            this.showToast(component, $A.get("$Label.c.Fail"), 'Error');
        } else if (state === "ERROR") {
            this.showToast(component, Error, 'Error');
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " + errors[0].message);
                    component.set("v.showLoadingSpinner", false);
            } else {
                console.log("Unknown error");

My issue is about the perfomance.

The apex method only invokes a future method so the transaction is fast, however the callback to javascript takes a few more seconds. When I have 30/40 parts it delays the whole process to some minutes.

I realized that the filePart, being a very large String, passing as an input is the most delaying cause. (Commenting that input turns the callbacks much more faster :P )

I found something about promises and I still try to perform the invocation outside the setCallback, since I really don't need the response. But I couldn't manage that.

Can you help me on that?



You must log in to answer this question.