0

I want to upload a file of the click of "save" btn and not upload it if the user click on "cancel" btn. But as soon as i select a file it automatically gets stored in data base without clicking any button.

.html

> <lightning-file-upload if:true={isShowSuspendModal}
> label={label.CPL_UploadFiles} name="fileUploader" accept={allowFiles}
> record-id={recordId}onuploadfinished={handleUploadFinished} multiple> 

on click of "Cancel" closeModal() will be called

.JS

closeModal(event){
            this.isShowSuspendModal = false;
}

But the file uploaded to the sandbox is still present.

1 Answer 1

0

In lightning-file-upload, the onuploadfinished is called after the file is successfully uploaded in salesforce. On clicking cancel you will have to manually delete the file by calling an apex method. Pass the uploaded file Id to the apex method to delete it.

handleUploadFinished(event){
    const uploadedFile = event.detail.files[0];
    this.documentId  = uploadedFile.documentId;
}

closeModal(event){
    this.isShowSuspendModal = false;
    
    //call apex method and pass documentId to delete the uploaded file
}

Another way would be to use lightning-input and handle file upload manually (only when user clicks on save button). Details here.

<lightning-input type="file"></lightning-input>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .