Instagram 如何命名上传的文件?

How does Instagram name uploaded files?

我最近对 ​​Instagram 及其 API 进行了一些研究,发现了其奇怪的文件命名。这是一个例子:

https://scontent-lhr3-1.cdninstagram.com/t51.2885-15/11357983_574786385995155_503550105_n.jpg

(图像应该只是黑色...)

我知道他们曾经像 this 这样命名文件,但我现在似乎找不到它们是如何命名的。这似乎是随机的,尽管我想知道 Instagram 如何命名他们的文件是否有任何模式。如有任何相关信息,我将不胜感激。

最好的猜测是他们使用随机。它是 Javascript,因此他们可能生成了一组随机数字以避免数据损坏。

他们在这个博客 post 中解释了一切:

https://engineering.instagram.com/sharding-ids-at-instagram-1cf5a71e5a5c

他们按照他们开发的自定义编号方案创建唯一 ID,使其为 64 位并保证唯一性:

Each of our IDs consists of:

  • 41 bits for time in milliseconds (gives us 41 years of IDs with a custom epoch)

  • 13 bits that represent the logical shard ID

  • 10 bits that represent an auto-incrementing sequence, modulus 1024. This means we can generate 1024 IDs, per shard, per millisecond

如果你想要一个实现示例,博客 post 解释得很好,但由于最初的问题不是关于如何获取文件名,而是关于文件名的来源,我觉得上面的引述是足够了。