中断上传文件

场景描述

选择文件后判断文件的类型、大小等是否满足需求,不满足需求中断文件上传

实现思路

在附件上传组件提供的“上传前”事件中控制

实现步骤

1.在附件上传组件的“上传前”事件中写代码

2.js中判断类型不满足需求时候通过message弹出提示信息,并使用下面两行代码中断上传

            event.preventDefault();
            return Upload.LIST_IGNORE;

注意:需要添加message和Upload的引用 import { message, Upload } from 'antd';

完整的案例代码如下:

    onUpload1BeforeUpload = (event) => {
        let {detail:{file,fileList}} = event;
        let isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
        if (!isJpgOrPng) {
            message.error('You can only upload JPG/PNG file!');
            event.preventDefault();
            return Upload.LIST_IGNORE;
        }
    }

results matching ""

    No results matching ""

    results matching ""

      No results matching ""