我应该在哪里存储照片?文件系统或数据库? [英] Where should I store photos? File system or the database?

查看:110
本文介绍了我应该在哪里存储照片?文件系统或数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:

  <一href=\"http://stackoverflow.com/questions/1105429/storing-uploaded-photos-and-documents-filesystem-vs-database-blob\">storing上传的照片和文件 - 文件系统VS数据库的blob

我开始开发一个Web应用程序,其主要目的是为了显示照片。用户将能够上传照片为好。

I am starting to develop a web app, the primary purpose of which is to display photos. The users will be able to upload photos as well.

这是来到了第一个问题是在哪里存储照片:文件系统或数据库上

The first question that came up was where to store the photos: on the file system or the database.

我将使用Windows框主办的网站。该数据库是MySQL和后端code是在利用C#ASP.NET MVC。

I will be using a Windows box to host the site. The database is MySQL and the backend code is in C# utilizing ASP.NET MVC.

推荐答案

文件系统,当然,除非你的目标就thedailywtf一个故事。最简单的方法是,使您可以从文件本身,如它的SHA-1散列获得属性组织的照片。然后,只需存储在数据库中的哈希,贴照片的主键和其他属性(谁上传,上传日期等)。

Filesystem, of course, unless you're aiming for a story on thedailywtf. The easiest way is to have the photos organized by a property you can derive from the file itself, such as its SHA-1 hash. Then just store the hash in the database, attached to the photo's primary key and other attributes (who uploaded it, upload date, etc).

这也是瓜分掉在文件系统中的照片是一个好主意,这样你就不会在同一个目录以百万计的文件结束。所以你有这样的事情:

It's also a good idea to divvy up the photos on the filesystem, so you don't end up with millions of files in a single directory. So you'll have something like this:

storage/00/e4/f56c0de1c61fdb926e79e8a0a65bd12930c9.jpg
storage/25/9a/ec1c55bfb660548a6770238668c4b117d92f.jpg
storage/5d/d5/4b01d98f17a9ad9dd1526b49ba39b5aa37a1.jpg
storage/63/49/6f740b6c284ce6685dc17d473a7360ace249.jpg
storage/b1/75/066d178188dde110149a8422ab651b0ee615.jpg
storage/b1/20/a2b7d02b7b0c43530677ab06235382a37e20.jpg
storage/da/39/a3ee5e6b4b0d3255bfef95601890afd80709.jpg

这也很容易端口,如果你曾经移动到分片存储。

This is also easy to port if you ever move to sharded storage.

这篇关于我应该在哪里存储照片?文件系统或数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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