[SalesForce] LWC file upload issue

I use the sample below to do the upload file in LWC:

html:

<template>
  <lightning-file-upload
        label="Attach receipt"
        name="fileUploader"
        accept={acceptedFormats}
        record-id={myRecordId}
        onuploadfinished={handleUploadFinished}
        multiple>
  </lightning-file-upload>
</template>

js:

import { LightningElement, api } from 'lwc';
export default class MyComponentName extends LightningElement {
@api
myRecordId;

get acceptedFormats() {
    return ['.pdf', '.png'];
 }

handleUploadFinished(event) {
    // Get the list of uploaded files
    const uploadedFiles = event.detail.files;
    alert("No. of files uploaded : " + uploadedFiles.length);
 }
}

But when I push to org., it cannot click the upload file button.
May I know what causing this issue?

Best Answer

Documentation: Usage Considerations

This component is not supported in Lightning Out or standalone apps, and displays as a disabled input. Additionally, if the Don't allow HTML uploads as attachments or document records security setting is enabled for your organization, the file uploader cannot be used to upload files with the following file extensions: .htm, .html, .htt, .htx, .mhtm, .mhtml, .shtm, .shtml, .acgi, .svg. For more information, see Upload and Share Files in Salesforce Help.

You need to check below:

  1. Don't allow HTML uploads as attachments or document records security setting

  2. Lightning Out or standalone apps - is not supported

Related Topic