September 24, 2026
File collision bug ? What's that ?
In the scenario where a file is uploaded to a system, if a previous copy of that same file existed on that system, in most cases it would…

By Chidera Onyegbule
1 min read
File collision bug ? What's that ?
In the scenario where a file is uploaded to a system, if a previous copy of that same file existed on that system, in most cases it would be overwritten.
For example, if a photo.jpg exists on a system PC and a second photo.jpg is uploaded, it would override or delete the first photo . Basically, the first uploaded photo would be deleted for the second one.
Apart from happening on personal PCs, it also happens on servers.
If an application is built to use users' media in mind, for example , profile pictures on a social media page, and it's not ordered well or structured well, a user would often overwrite/delete another person's media. For example, two users may upload profile pictures with the same name, but the second one comes in and overrides the first.
However, there are different fixes to this. One common fix is to generate your own personal name instead of using the uploaded name.
So instead of profile-pic.jpg, we would remove the "profile-pic" and give it a unique but distinct name like bg2424.jpg, or generate a name using a UUID or another type of ID
Another approach is to organize it into folders. So if two users are uploading the same picture, then instead of uploading it into the same storage, we create folders in that storage for the users. So instead of "media/profile-pics.jpg" where one picture gets overridden, we use "media/user-1/profile-pics.jpg" and "media/user-2/profile-pics.jpg". Both files keep the same name but are distinguished based on where they are stored on the server.
Another approach is to hash the file content by running the binary data through a hashing function like MD5 or SHA256. Hashing this file often gives what is known as a fingerprint, and this fingerprint would be used to name the media file.
This third approach is similar to the first approach, but instead of just generating our names, we use the hashing of the file to generate our names.