如下代碼,再 沒有 添加 file.type 類型為 "" 時候,上傳 .zip文件再某些環境中會被攔截,提示' 請上傳正確格式的附件!' 。這是 upload 對zip 的type分解時候分解為 “” 。因該分解為 ’application/x-zip-compressed‘,這個時候把 “” 也加進允許隊列。還有一個.rar文件在上傳的時候會被判定為 file.type = "" 。 所以說 upload 在有些環境可能把2這搞混亂了。
const fileProps = { name: "multipartFile", listType: 'select', tipMsg: '支持擴展名:.zip,需包含excle和文件夾,僅允許上傳一個文件', action: `${globalInitConfig.mdm_url}/mdm/api/innovation/patent/import_data`, onlySelectFile: true, beforeUpload(file) { const isJPG = file.type === 'application/x-zip-compressed' || file.type == "" if (!isJPG) { Message.error('請上傳正確格式的附件!'); return isJPG; } if (_this.state.fileList.length > 0) { Message.error('僅允許上傳一個文件!'); return false; } _this.setState({ fileList: [file] }) },