存储图像的目录结构 ASP.NET - 需要建议

发布于 2024-10-02 10:31:26 字数 826 浏览 1 评论 0原文

我正在开发一个应用程序,该应用程序将在第一年存储大约 50,000 张图像,在第二年存储另外 75,000 张图像。图片可以来自图库、新闻图片、文章图片和个人资料图片。所以我想给每个图像一个GUID并将该GUID存储在数据库中。

至于目录结构,我想到的是这样的:

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

所以我使用 GUID 的前 4 个字符作为我的目录结构,以便在目录之间更均匀地传播图像。

现在我对这种方法有一些疑问:

  • 将所有不同类型的图像存储在一起而不是使用 ~/Images/Upload/Profiles~/Images/Upload/Articles 是否被认为是良好的做法 等。
  • 我还存储缩略图,并且它们显然有不同的 GUID,因此缩略图不会与原始缩略图位于同一文件夹中,不知怎的,这并没有给我带来良好的感觉,但我想这应该不重要。
  • 画廊也是如此,我习惯将画廊存储在像 ~/Images/Upload/Galleries/12 这样的文件夹中,现在画廊中的所有图像将分散在不同的子文件夹中,是这样的性能大受影响?
  • 你们对目录结构还有其他想法吗?

正如您可能看到的那样,我有点害怕使用这种方法,但由于会有很多图像,甚至可能比我给出的数字还要多,我想我必须放弃控制:)

请给我您对此的意见,谢谢非常喜欢你。

亲切的问候, 标记

编辑
忘了说了,图片也会经常被删除

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.

Kind regards,
Mark

Edit:
Forgot to mention, images will be deleted fairly often also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

因为看清所以看轻 2024-10-09 10:31:26

我唯一的评论是建议您不要按照计划进行目录操作;相反,看看是否可以对文件夹结构进行某种逻辑组织。我敢打赌,您最终可能会因为这种基本上随机的目录结构而烦恼不已。

但请记住暴露私人信息的可能性;例如,如果用户名尚未公开,您可能不应该拥有显示用户名的目录结构。

一种可能性;让它们基于时间...例如~/Images/Upload/2010/11/15。如果这看起来不错,就走得更远,或者如果你愿意,就不要走得太远。 (例如,仅转到月份;或者执行周数而不是日期)。我还建议在这种方案中保留前导 0,以便于排序。

再说一次;根据您如何使用它们,这样的结构可能也不好。这只是我脑海中突然出现的想法:)

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 :)

万水千山粽是情ミ 2024-10-09 10:31:26

我将在数据库中存储所有这些图像的基础上设计我的数据模型。忘记弄乱目录。然后只需创建高效的 HttpHandler 即可将图像流式传输回来。

如果您要将路径存储在数据库中并将图像存储在目录中,我的目标是使路径尽可能简单。最佳性能平衡可能取决于图像的大小;您可能需要查看 FileStream 类。

一些资源:

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

在数据库中存储图像 - 是还是不?

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

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

陌路黄昏 2024-10-09 10:31:26

我认为您还可以使用 sql server 2008 文件流功能来存储图像并更好地管理它们。

因为在文件流功能中,您可以物理存储图像并通过 SQL Server 管理它们。因此,您可以同时利用这两个优势。

这里有一些很好的链接
http://www.simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/" simple-talk.com/sql/learn-sql-server/an-introduction-to-sql-server-filestream/

http://weblogs.asp.net/aghausman/archive/2009/03/16 /保存和检索文件-using-filestream-sql-server-2008.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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文