高章伟
2023-03-28 fa01cf80171eb10c7f1b4f1764376397b714c526
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
({
 
    upload: function(component, file, base64Data) {
        var action = component.get("c.predict"); 
        var modelId = component.get("v.modelId"); 
        action.setParams({
            fileName: file.name,
            content: base64Data, 
            modelId: modelId
        });
        action.setCallback(this, function(a) {
            component.set("v.waiting", false);
            var state = a.getState();
            if (state === 'ERROR') {
                console.log(a.getError());
                alert("An error has occurred");
            }
            var result = a.getReturnValue();
            var predictions = [];
            if (result && result.length) {
                for (var i=0; i<result.length; i++) {
                    predictions.push({
                        label: result[i].label,
                        formattedProbability: '' + Math.round(result[i].probability * 100) + '%'
                    });
                }
                component.set("v.predictions", predictions);
                var myEvent = $A.get("e.c:EinsteinVisionEvent");
                myEvent.setParams({
                    "predictions": result
                });
                myEvent.fire();
            }
        });
        component.set("v.predictions", null);
        component.set("v.waiting", true);
        $A.enqueueAction(action); 
    }
 
})