开发者

Directory structure for storing images ASP.NET - Advice needed

I'm working on an application which will store around 50.000 images within it's first year and another 75.000 in it's second. Images can come from Galleries, news images, article images and profile images. So I want to give each image a GUID and store the GUID in the database.

As for the directory structure i was thinking of something like this:

~/Upload/Images/F2/50/F2504E0-4F89-11D3-9A0C-0305E82C3301.jpg

So I'm using the first 4 characters of the GUID as my directory structure to spread images a bit more evenly between directories.

Now I have some questions about this approach:

  • Is it considered good practice to store all different kinds of images together rather then use ~/Images/Upload/Profiles, ~/Images/Upload/Articles etc.
  • I'm also storing thumbnails and they have a different GUID obviously so the thumbs will not be in the same folder as the original and somehow that doesnt give me a good feeling but I guess it should not matter but.
  • Same goes for Galleries, I'm used to store galleries in folders like ~/Images/Upload/Galleries/12 , and now all the images from a gallery will be scattered around in different subfolders, is this a big performance hit?
  • Do you guys have any other ideas for directory structures?

As you can probably see I'm a bit afraid to use this approach but since there will be lots of images maybe even more then the numbers i gave i have to let the control go I think :)

Please give me your opinions on this thank you very much.

开发者_如何学JAVA

Kind regards, Mark

Edit:

Forgot to mention, images will be deleted fairly often also


My only comment is to suggest you do not do the directories as you plan to; Instead, see if you can put some sort of logical organization to the folder structure. I'd be willing to bet you might end up pulling a hair or two out with that, essentially random, directory structure.

Keep in mind the possibility of exposing private information, though; You probably shouldn't have directory structure which reveals user names if they are not already public, for example.

One possibility; have them be based on time... ~/Images/Upload/2010/11/15 for example. Go further if that seems good, or not as far if you prefer. (only go to the month, for example; or do week number instead of day). I'd also recommend keeping leading 0's with such a scheme, for ease of sorting.

Then again; depending on how you are using them, such a structure might not be good, either. It was just the thought that popped into my head :)


I'd design my data model on the basis of storing all these images in the DB. Forget messing around with the directory. Then just create efficient HttpHandlers to stream the images back.

If you are going to store the paths in the DB and the images in the directory, I would aim to keep the paths as simple as possible. The best performance balance may depend on the size of the images; you may want to look at the FileStream class.

Some resources:

http://www.homeoftester.com/viewtopic.php?t=2648&sid=2f86787a27a5690db35df9b61f9e8247

Storing Images in DB - Yea or Nay?

http://www.sqlskills.com/BLOGS/PAUL/post/High-performance-FILESTREAM-tips-and-tricks.aspx


I think you could also use sql server 2008 file stream feature for the storing images and better managing them.

Because In file stream feature you can store image physically and manage them via SQL Server. So you can take both advantages.

Here are good links for that http://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/

http://weblogs.asp.net/aghausman/archive/2009/03/16/saving-and-retrieving-file-using-filestream-sql-server-2008.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜