ant-design Upload.Dragger can't trigger beforeUpload when accept is not empty

7cwmlq89  于 4个月前  发布在  其他
关注(0)|答案(7)|浏览(119)

Steps to reproduce

  1. I hava a accept attribute of Upload.Dragger component, now I need upload a file which extension doesn't match accept
  2. click to upload, beforeUpload triggered
  3. drag to upload, beforeUpload not triggered

What is expected?

drag to upload, beforeUpload also triggered

What is actually happening?

drag to upload, beforeUpload not triggered
| Environment | Info |
| ------------ | ------------ |
| antd | 4.21.4 |
| React | 18.2.0 |
| System | win10 |
| Browser | edge 102 |

I want to do some checking work on beforeUpload hook. but when drag file into box, beforeUpload not triggered.

bqjvbblv

bqjvbblv1#

same issue not solved at 2019. #17090

pjngdqdw

pjngdqdw3#

#30403 (comment)
我是 windows系统,可以选择非 accept 文件,此时 beforeUpload 还是没有触发的。
https://github.com/react-component/upload/pull/329/files 看起来没有解决这个问题

iklwldmw

iklwldmw5#

@afc163 目前添加 accept 属性,Dragger 拖入非 accept 的文件没有走到 beforeUpload,有什么方案可以处理下

tnkciper

tnkciper6#

@afc163 目前添加 accept 属性,Dragger 拖入非 accept 的文件没有走到 beforeUpload,有什么方案可以处理下

+1 当用户拖入非 accept 的文件,目前是没有任何反应的。我想要弹出message(例如”该类型文件不支持“),好像没法实现。只有onDrop会触发,但onDrop里只有DragEvent,没有file的信息。

nhhxz33t

nhhxz33t7#

可以在 DragEvent 中拿到 file

function handleDrop(event: DragEvent) {
  const files = event.dataTransfer?.files;
  if (files) {
    const filesArr = Array.from(files);
    filesArr.forEach((file) => {
      // 校验
    });
  }
}

相关问题