You need to sign in to do that
Don't have an account?
Raghu Chengalvarayan
Lightning File Upload control and validation
I'm using the lightning file upload control to store fiels upto 16MB in size. However I need to validate the resolution of the file and size. I understand this is possible only in client side using HTML 5 Canvas. But the new lightning file upload control doesn't expose any client side event. It provides an event after the file is saved to server, which is not helpful. The lightning control uses a generic html input. I tried attaching the client side event to the input tag in helper.js and render.js, but no luck. Any ideass, how to hook the event to the input control? Is Locker preventing this?
I would recommend using the lighting-input with type of 'File' and onchange event handler. within the handler, you will can get the file name & size.Below are some codes I can think of:
<lightning-input label="" name="file uploader" onchange = {handleFileChange} type="file" multiple></lightning-input>
handleFileChange(event){
if(event.target.files.length > 0){
this.filesUploaded = event.target.files;
this.fileName = event.target.files[0].name;
this.filesize = event.target.files[0].size;
}
}
hope this work for you!
Yufu