我希望将上传的文件数量限制为10个,如果数量仅超过10个,则会显示一条错误消息.但是,如果我try 一次上传11个文件,我的屏幕上会出现11次错误信息.
const beforeUpload = (file,fileList) => {
const maxFileSize = 250 * 1024 * 1024; // 250MB limit
const maxLimit = 10
if (fileList.length>maxLimit){
message.error(`Only 10 files allowed`);
return false;
}
if (file.size > maxFileSize) {
message.error(`${file.name} file upload failed (exceeds 250MB)`);
console.error("File size exceeds the limit of 250MB");
return false;
}
return true;
};
我试着在bepreUpload中处理它,但如果它超过10个文件,我可以禁用文件上传.但是,我一次都不能显示该消息.如果我try 上传11个文件,它会显示11次.关于如何显示一次消息并限制文件上传,有什么 idea 吗?
<Upload.Dragger multiple beforeUpload={beforeUpload} customRequest={handleFileUpload} showUploadlist={false}>...</Upload.Dragger>
个