图片网址命名方案 [英] Image URL Naming Scheme

查看:142
本文介绍了图片网址命名方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

序言:我正在建立一种CMS/社交网络服务,该服务将托管许多图像.

Prologue: I'm building a sort of CMS/social networking service that will host many images.

我打算使用Eucalyptus/Amazon S3存储图像,并想知道Tumblr,Twitter和& c等网站使用的看似随机文件名的重要性

I'm intending on using Eucalyptus/Amazon S3 to store the images and was wondering about the significance of the seemingly-random file-names used by sites like Tumblr, Twitter, &c., e.g.

31.media.tumblr.com/d6ba16060ea4dfd3c67ccf4dbc91df92/tumblr_n164cyLkNl1qkdb42o1_500.jpg

pbs.twimg.com/media/Bg7B_kBCMAABYfF.jpg

它们如何生成这些字符串,与仅为每个文件名增加一个整数相比,这有什么好处?也许只是随机字符?也许哈希一个整数?

How do they generate these strings, and what benefits does this incur over just incrementing an integer for each file name? Maybe just random characters? Maybe hashing an integer?

谢谢!

推荐答案

Twitter使用一种称为雪花"的编码方法.有

Twitter uses an encoding method called 'snowflake'. There is github source

基本格式编码一个时间戳(42位),数据中心ID(5位)和工作人员ID(数据中心的计算机; 5位)

The basic format encodes a timestamp (42 bits), data center id (5 bits), and worker id (the computer at the data center; 5 bits)

对于tweet ID,它们将值写为长十进制数. Tweet ID'508285932617736192'是十六进制值'070DCB5CDA022000'.前42位是时间戳(time_t值为070DCB5C +纪元1291675244).接下来的五位是数据中心(在本例中为"1"),接下来的五位是工作程序ID("2").

For tweet IDs, they write the value as a long decimal number. Tweet ID '508285932617736192' is hex value '070DCB5CDA022000'. The first 42 bits are the timestamp (the time_t value is 070DCB5C + the epoch, 1291675244). The next five bits are the data center (in this case, '1'), and the next five bits are the worker id ('2').

对于图像,它们执行的操作完全相同,但是使用base64编码(遵循RFC 4648标准进行URL编码;最后两个base64字符是连字符和下划线).

For images, they do the exact same thing, but use base64 encoding (following the RFC 4648 standard for URL encoding; the last two base64 characters are hyphen and underscore).

BwjA8nCCcAAy5zA.jpg解码为2014-09-02 20:23:58 GMT,数据中心1,工作者#7

BwjA8nCCcAAy5zA.jpg decodes as 2014-09-02 20:23:58 GMT, data center #1, worker #7

这篇关于图片网址命名方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆