I need to show a custom error message in lightning-file-upload when we tried to upload the unacceptable format of the file.

            label="Attach receipt"

it does not have any property to set custom error messages?

What I tried so far?

I have tried accessing the component in the renderedCallback method. But No success.


I cannot use toast to show error in lightning-file-upload because it does not have any such method like onerror.

  • Is it still calling the handleUploadFinished method when the file format is incorrect? If so, you should just handle the error there and delete the file if it actually saved to Salesforce. If not, I can't help you there. Still just beginning my LWC training (I'm pretty much working with just aura components at the moment). – Roti Oct 18 '19 at 20:39
  • @sanket Were you able to get solution for this? I have the same problem – devforce Jul 6 at 10:51

In the docs it says you can use your custom validity error messages using HTML 5's api.

    <lightning-input class="inputCmp"
                     label="Enter your name:">
    <lightning-button label="Register"
import { LightningElement } from 'lwc';
export default class MyComponent extends LightningElement {

    register(event) {
        var inputCmp = this.template.querySelector(".inputCmp");
        var value = inputCmp.value;
        // is input valid text?
        if (value === "John Doe") {
            inputCmp.setCustomValidity("John Doe is already registered");
        } else {
            inputCmp.setCustomValidity(""); // if there was a custom error before, reset it
        inputCmp.reportValidity(); // Tells lightning-input to show the error right away without needing interaction
| improve this answer | |
  • This will not work with lightning-file-upload. – devforce May 18 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.