我使用 antd design ,它使文件上传良好。
<Upload {...props}>
<Button icon={<UploadOutlined />}>Upload png only</Button>
</Upload>
在这里,我有一个 toferplaod
函数,它的代码看起来
const beforeUpload = (file) => {
const isPNG = file.type === "image/png";
if (!isPNG) {
message.error(`${file.name} is not a png file`);
}
// return Upload.LIST_IGNORE; (This will work in newer version but I am using older one which is 4.9.4.
}
像我在上述代码中提到的那样,如果上传的映像不是png,则它将从当前列表中删除一个上载,因为我们使用 upload.list_ignore
,但不幸的是,我正在版本4.9.4 中工作,并且没有任何这样的关键字可以从列表中删除无效的上传。
您能帮助我从版本4.9.4的列表中删除上传的无效项目吗?
工作示例:
a>
结果:
尝试过一些尝试后,我阻止了文件在列表中显示在列表中,如果该文件不有效,但不幸的是,上传文件的删除现在不起作用(之前正常工作当前的实现)。
I am having a file upload using Antd design and it makes the file upload fine.
<Upload {...props}>
<Button icon={<UploadOutlined />}>Upload png only</Button>
</Upload>
Here I have a beforeUplaod
function and its code looks like,
const beforeUpload = (file) => {
const isPNG = file.type === "image/png";
if (!isPNG) {
message.error(`${file.name} is not a png file`);
}
// return Upload.LIST_IGNORE; (This will work in newer version but I am using older one which is 4.9.4.
}
As I have mentioned in the above code, if the uploaded image is not png then it will remove the uploaded one from current list as we use Upload.LIST_IGNORE
but unfortunately I am working in a older version 4.9.4 and it doesn't have any such keyword to remove the inValid upload from the list.
Could you please kindly help me to remove the uploaded invalid item from the list for version 4.9.4?
Working example:
Result:
After some try, I have prevented the file to display in the list if it is not valid but unfortunately the delete of the uploaded file doesn't work now (which was working fine before this current implementation).
发布评论
评论(2)
我能够通过实现
onRemove
处理程序来删除选定/上传的文件。示例:
in-reaCtjs“>
I was able to get the removal of selected/uploaded files by implementing an
onRemove
handler.Example:
您可以创建一个状态&amp;控制filelist。在新版本中,我们可以使用upload.list_ignore,但可以查看
api段
。如果您不想上传文件,则可以简单地返回false或使用Promise,可以使用recond(false)
拒绝。在上传组件的API部分中查看
the upload
。https://ant.design/components/upload/upload/#api
https://i.sstatic.net/lzgbm.png“ rel =“ nofollow noreferrer”>
希望这能解决您的问题
You can create a state & control the fileList. In new version, we can use Upload.LIST_IGNORE but have a look at the
API Section
. If you do not want to upload the file, you can simply return false or if you use promise, you can reject withreject(false)
.Have a look at
beforeUpload
in API Section of Upload Component.https://ant.design/components/upload/#API
Hope this solve your problem