How to generate a unique hash for a URL?

前端 未结 12 1417
时光取名叫无心
时光取名叫无心 2020-12-28 08:11

Given these two images from twitter.

http://a3.twimg.com/profile_images/130500759/lowres_profilepic.jpg
http://a1.twimg.com/profile_images/58079916/lowres_pr         


        
12条回答
  •  悲哀的现实
    2020-12-28 08:47

    The nature of a hash is that it may result in collisions. How about one of these alternatives:

    1. use a directory tree. Literally create sub directories for each component of the URL.
    2. Generate a uniques id. The problem here is how to keep the mapping between real name and saved id. You could use a database which maps between a URL and generated unique id. You can simply insert a record into a database which generates unique ids, and then use that id as the filename.

提交回复
热议问题