//我想使用antdesign的upload组件只接受视频文件。
const beforeUpload = (file) => {
const isVideo = file.type === 'video/*'; //using (video/*) is not working here to accept any video file.
console.log('fle type', file.type);
if (!isVideo) {
message.error('You can only upload video file!');
}
const isLt10M = file.size / 1024 / 1024 < 10;
if (!isLt10M) {
message.error('Video must smaller than 10MB!');
}
return isVideo && isLt10M;
};
const handleChange = (info) => {
console.log('info', info);
};
render(
<Upload beforeUpload={beforeUpload} onChange={handleChange}>
<Button icon={<UploadOutlined />}>Click to Upload</Button>
</Upload>
)
//如果有什么办法可以解决这个问题请告诉我
试试regex:
const regex = /video/.*/g;
const isVideo = regex.test(file.type);