D
D
djhox2018-10-11 17:55:47
Backend
djhox, 2018-10-11 17:55:47

How to protect against duplication of files when uploading to the server?

What is the best way to save files on the server?
Previously, I wrote down an md5 hash for each file and, when uploading, I checked the hash of the new file with the one in the database, and if such a hash exists, the file was not uploaded, but the id of the previous uploaded file was given.
But, as I understand it, there is a high probability of a collision with md5. What is the best way to check files for duplicates then?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-10-11
@djhox

1) Store several different hashes, there are other algorithms besides md5
2) Before md5, also compare just the size
3) If EVERYTHING matches - for a complete exception - compare byte by byte

R
Roman Mirilaczvili, 2018-10-12
@2ord

You can simply replace the hashing algorithm with BLAKE2b.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question