在使用<input type="file" />
这个标签来上传文件的时候指定上传文件类型
关键: 使用accept
属性
比如: <input className={styles.fileEle} onChange={this.onImportExcel} type="file" accept=".xls, .xlsx" />
注意: 指定多种类型的话, 中间使用,
分隔
下面是常见类型后缀表
*.jpeg | image/jpeg | JPEG |
*.doc | application/msword | MS Word Document |
*.gif | image/gif | Graphic Interchange Format |
*.htm | text/html | HyperText Markup Language |
*.html | text/html | HyperText Markup Language |
*.jpe | image/jpeg | JPEG |
*.jpeg | image/jpeg | JPEG |
*.jpg | image/jpeg | JPEG |
*.mp3 | audio/mpeg | MPEG Audio Stream, Layer III |
*.mp4 | audio/mp4, video/mp4 | MPEG-4 Audio/Video |
| application/pdf | Portable Document Format |
*.png | image/png | Portable Network Graphics |
*.ppt | application/vnd.ms-powerpoint | MS PowerPoint Presentation |
*.txt | text/plain | Plain Text |
*.xls | application/vnd.ms-excel | MS Excel Spreadsheet |
*.xml | text/xml, application/xml | Extensible Markup Language |
*.zip | aplication/zip | Compressed Archive |
*.wps | application/vnd.ms-works | Works Text Document |