What are the advantages and disadvantages of not renaming a file when uploading it locally?

recently participated in a project in which there is a file upload function. The way to see it is to create a folder according to the current year, month and day, and then save the file in the corresponding folder. If the file has the same name, it will be followed by + underscore + sequence number. What are the advantages and disadvantages of this approach in terms of security or other?

Mar.29,2022

feels like an optimistic lock, but it is difficult to implement if you use the file name as the version number.
in addition, if you upload it, you have to download it or how to check it, right? If you need to record a file name in a certain location, why not just randomly generate a file name


this is no problem, as long as you can ensure that the file name does not repeat, if it is multi-threaded storage, there will be no problem if you write a file and remember to lock it.


advantages:

  1. is easy to find manually. If you want to see some resources, just click on the folder to find it.

disadvantages:

  1. there is a possibility of downloading files being stolen. As long as you see your naming, you can find non-personal files to download according to the naming law.
In addition, I'm not sure how you correspond the file to the user, but in this way, the guess is to store the path of the file and associate it with the user. If possible, you can encrypt the file with MD5, and wouldn't it be better to use the generated key as the id, of the file?

Menu