开发者

Image file structure and encoding filename. like Facebook image Urls

I'm wondering whats the best folder structure for a web application to save users images if they have different usernames and different albums. I'm using Amazon S3, folders and buckets

I don't want people to be able to predict the urls for users/albums like FB

http://sphotos.ak.fbcdn.net/hphotos-ak-snc4/hs1189.snc/154140_10150322456245277_731310276_15908482_4918209_n.jpg

Also for the filename. Whats the b开发者_高级运维est type of information to encode to change the filename to. (username, date/time, user id) E.g.

Original: apple.jpg

Encoded: 1263547483_56783929_3934736_943883.jpg

What would you use to encode these Url safe filenames? Base64, MessageDigests?


I'd create "random" file name. The files may be saved either in one directory or in generated directories structure like dir01, dir02, dir03. Separate directories are better for really big amounts of files. I think that you should not store more than 10K files in one directory. If you have more files create new directory every time counter arrives to 10K.

All metadata of files including the physical path in file system should be stored in DB. Files table may contain foreign key to users table, so you can always know the file's owner.

This design is scalable: in future you can store different directories on separate disks or even use CDN system. This is secure enough. It is impossible to guess how do you encode the file metadata into file name because you do not encode anything: you just create random name. It is simple & powerful. All data is in DB, so you can add new features in future and run them on the old data in DB.


Encoding with ex Base64 seem like a bad idea. I would simply replace the filename by a GUID and have a map in a database that mapped the file and the GUID together.

Something like:

http://photos.site.com/{account-id}/{gallery-id}/{image-guid}.jpg

Which would result in:

http://photos.site.com/23323/323/F66A80B2_007F_11E0_86C8_322ADFD72085.jpg
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜