I have a custom object that has an attached (png) image to it. I'm trying to create a lightning component that pulls the attachment and draws it on a html canvas. So far in the below code, I'm able to get the img tag to show the attachment. However I cannot find a way for my helper/controller to grab that image and actually draw it on the canvas. How could I accomplish this?
.cmp:
<aura:component controller="ScreenshotEditorComponentController" implements="flexipage:availableForAllPageTypes, force:hasRecordId" access="global">
<aura:handler name="init" action="{!c.init}" value="{!this}" />
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="screenshot" type="Attachment" />
<canvas aura:id="canvas" id="canvas" width="500" height="500"></canvas>
<img aura:id="img" src="{!'/servlet/servlet.FileDownload?file=' + v.screenshot.Id}" onload="{c.test}"/>
</aura:component>
controller:
({
init: function(component, event, helper) {
helper.getData(component, component.get('v.recordId'));
}
})
helper:
({
getData: function(component, recordId) {
var action = component.get('c.getScreenshotData');
action.setParams({
screenshotId: recordId
});
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === 'SUCCESS') {
component.set('v.screenshot', response.getReturnValue());
}
});
$A.enqueueAction(action);
},