I have a drop zone for files in a JS application. I want to filter out duplicate files being dropped into the application, but I can't seem to find a proper way to compare two File
objects pointing to the same file. All I could find is comparison by "name + file size + modified date" combo, but it's not 100% proof, since the path is not revealed in the name
attribute.
Is there a way to do it that I just missed?
I know that the answer comes too late, but I was confronting with the same issue and maybe others too.
I doubt that there is a better method than the one that you're using. Indeed it's not 100% proof because you can have two files with the same name, size and last modified date, but they can sit in two separate folders and be different.
Using equality (===
) between File
objects is also failing if you have the same file chosen by two different <input type="file">
.
I think another way will be in addition to what you've done to use FileReader
to actually compare the files by content. But this will be very expensive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With