将用户的图像存储在 Web 应用程序中

发布于 2024-11-04 03:15:18 字数 447 浏览 6 评论 0原文

我目前正在 JSP/Servlet 中开发一个 Web 应用程序。
该应用程序允许用户为每个用户帐户上传图像文件。

存储图像的最佳方式是什么?
在您回答之前,请考虑我希望拥有的以下功能;

  1. 我现在正在使用 MySQL,但可能会转移到其他数据库。

  2. 我可以将图像存储为平面文件,但我希望admin 帐户可以选择备份整个数据库并稍后重新加载。理想情况下,备份/重新加载也应该适用于图像。 (即使备份是从不同的物理计算机完成的,并且重新加载是从不同的计算机完成的)

  3. 使用 BLOB/CLOB 是解决问题 2 的一个选项。
    但是,如果我的数据库变得非常大怎么办?

I have a web application currently being developed in JSP/Servlets.
The application allows users to upload image files for each user account.

What is the best way to store the images?
Please consider the following features that I'd like to have before your answer;

  1. I am using MySQL now, but there could be a possibility of moving to a different database.

  2. I can store the images as flat files, but I want the admin account to have an option to backup the complete database and reload it later. Ideally the backup/reload should work with the images too. (even if the backup was done from a different physical machine and reload was done from a different machine)

  3. Using BLOB/CLOB is an option that solves problem 2.
    But, what if my database becomes very large?

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

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

发布评论

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

评论(3

我不吻晚风 2024-11-11 03:15:18

对于您的情况,我强烈建议您在数据库上有一个 blob 字段并在其中存储图像。主要是因为这对于他们来说是正确的地方。因此,创建一个 Servlet,从数据库中检索指定用户的图像。例如,/userimage?name=john

关于您的“大小/性能”问题:

  • 数据库(除其他外)是为了存储和交换大量数据
    因此,它们是最好的选择

  • 即使您将它们存储在其他网站上,它们仍然会减少可用空间和性能。

  • 如果您确实想要管理大型数据(>= 3TB,不是您的情况),那么您可以将它们存储在文件系统上并将文件名保存在数据库中。有关详细信息,请查看此问题

In your case, I strongly recommend you having a blob field on your database and store the images in it. Mainly, because this is the correct place for them. So, make a Servlet that retrieves the image of the specified user from the database. For example, /userimage?name=john.

About your "size/performance" problem:

  • Databases were made (among other things) to store and exchange large amounts of data.
    So, they're the best option.

  • Even if you store them on other sites, they will still reduce free space and performance.

  • If you really want to manage LARGE data (>= 3TB, not your case) then you can store them on a file system and save the filenames in the DB. For more info, look at this question.

絕版丫頭 2024-11-11 03:15:18

将它们存储在文件系统中。它更快更简单。通常,在访问图像时,您必须先将其保存到文件中,然后才能使用它。您可以使用第三方工具检查图像。您可以将 recordID 存储在文件名中,以防止图像/记录关联被破坏。

许多其他人也同意这个观点: http://forums.asp.net/p/1512925/3610536 .aspx

Store them in the file system. It's faster and simpler. Often, when accessing an image, you're going to have to save it to a file anyway before you can utilize it. You can examine the images with third party tools. You can store the recordID in the filename to keep the image/record association from ever being broken.

Many others share this opinion: http://forums.asp.net/p/1512925/3610536.aspx

一向肩并 2024-11-11 03:15:18

只需将它们存储在数据库中......如果您的用户群“变得非常大”,您将有大量现金来购买可以处理负载的数据库服务器(甚至是它们的农场),现在不会'你呢?

Just store them in the DB... if your user base "becomes very large" you'll have buckets of cash to buy a balls-out database server (or even a farm of them) which can handle the load, now won't you?

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