是否有特殊原因为什么在线服务经常以半随机名称存储图像[关闭]

In real practice we see user uploaded image with name like 84b222882da311e284b222000a1fbcf6_7.jpg

Isn't it much easier and structured to just store image as /username/101.jpg /username/102.jpg (For example you can have a database table for images and you can then simply use the index as file name.)

What are the practical consideration here? I guess one would have to check every time whether a newly generated random name is not in the database? Is there concern about obfuscation?

Typically it's done for two reasons.

  1. To have unique filenames.
  2. Makes it difficult to guess image filenames (stops people from just entering the next image in the URL and seeing the image).

Isn't it much easier and structured to just store image as /username/101.jpg /username/102.jpg

Not at all. That way requires a directory listing to get the highest number used, and presents issues with deletions - do you reuse the ID? 101.jpg and 102.jpg are at least as arbitrary as 84b222882da311e284b222000a1fbcf6.jpg, which is likely a hash of the file content or the file's ID in the database.