I have a file upload LWC component that used to work but now it's throwing an "uploadn.map is not a function error" when I call reader.readAsDataURL(file). I imagine updates to locker service are to blame but wondering if anyone else has run into this or if there's a solution? At the end of the day I just want to upload an image
<template if:true={showUpload}>
<lightning-input type="file"
accept=".png, .gif, .jpg, .jpeg"
label="" onchange={updateSignature} data-id="fileupload"></lightning-input>
</template>
updateSignature(event) {
let file = event.target.files[0];
console.log(event.target.files[0]);
if(!file) {
const toast = new ShowToastEvent({
"title" : "Error",
"message": "Please select a file",
"variant": "error"
});
this.dispatchEvent(toast);
return;
}
let reader = new FileReader();
reader.onload = () => {
let parts = reader.result.split(',');
updateSignatureImage({recordId: this.recordId, base64Image: parts[1]}).then(result => {
this.update = false;
this.uploaded = true;
refreshApex(this.getRecord);
getRecordNotifyChange(this.recordId);
const toast = new ShowToastEvent({
"title" : "Success!",
"message": "Signature image updated successfully",
"variant": "success"
});
this.dispatchEvent(toast);
}).catch(error => {
const toast = new ShowToastEvent({
"title" : "Error",
"message": "Signature image failed to upload"+error.message,
"variant": "error"
});
this.dispatchEvent(toast);
})
}
console.log('readingDataUrl');
reader.readAsDataURL(file);
}
lightning-file-upload
should be used. Why don't you use it? Do you understand that even if you were able to make the existing solution work, it would be limited to 4MB files only since you can't process any bigger files in Apex due to heap size limit?