简体   繁体   中英

ANTD upload accept file of different format

Iam using antd upload. I need to accept files of format.xls and.xlsx. How multiple files formats added in antd. My code is like,

const { Dragger } = Upload;
    <Dragger accept=".xlsx"
        previewFile={false}
        showUploadList={false}
        beforeUpload={(e) => {
        var name = e.name.replace(".xlsx", "");
        if (name.indexOf(',') > -1) {
        name = name.replace(",", "");
        }
        if (name.indexOf(' ') > -1)
         name = name.replace(" ", "");
        if (this.state.IsLargeFile) {
         this.setState({ uploded: true, LargeFileName: name });
         this.form.setFieldsValue({ fileContent: 'a', fileName: name })
         }
         else {
         toBase64(e).then((res) => {
          this.setState({ uploded: true });
          this.form.setFieldsValue({ fileContent: res, fileName: name })
           })
             }
             return false;
              }}
              multiple={false}>
           <p className="ant-upload-drag-icon">
        {this.state.uploded ? <CheckCircleOutlined style={{ color: 'green' }} /> : <InboxOutlined />}
       </p>
     <p className="ant-upload-text">Drop Document to upload or click to browse</p>
       <p className="ant-upload-hint">
       Only Excel file is supported.
          </p>
         </Dragger>

How to accept both.xls and.xlsx file?

You can use the "accept" prop to specify the file types that you want to accept. For example, if you want to accept both.xls and.xlsx files, you can use the following code:

<Dragger accept=".xls,.xlsx" /> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM