upload component in antdesign



//我想使用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);

相关内容

  • 没有找到相关文章

最新更新