【问题标题】:ANTD upload accept file of different formatANTD上传接受不同格式的文件
【发布时间】:2023-01-30 21:32:49
【问题描述】:

我正在使用 antd 上传。我需要接受格式为 .xls 和 .xlsx 的文件。 antd 中如何添加多种文件格式 我的代码就像,

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>

如何同时接受 .xls 和 .xlsx 文件?

【问题讨论】:

    标签: reactjs antd


    【解决方案1】:

    您可以使用“accept”属性来指定您想要接受的文件类型。例如,如果要同时接受 .xls 和 .xlsx 文件,则可以使用以下代码:

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

    【讨论】:

      猜你喜欢
      • 2015-12-30
      • 1970-01-01
      • 2012-10-02
      • 2012-05-12
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      相关资源
      最近更新 更多