将图像存储在数据库中而不是文件系统中 [英] Storing images in a database versus a filesystem

查看:95
本文介绍了将图像存储在数据库中而不是文件系统中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道在使用数据库进行文件存储(特别是图像)的讨论中失去了多少论据和生命。在决定如何进行我的项目时,我有点不高兴。

Well we all know how many arguments and lives have been lost with the discussion of using databases for file storage (images specifically). I'm in a bit of a pickle when it comes to deciding on how to proceed with my project.

我有一个网站,允许管理员上传员工照片。现在,这些图片存储在我的MySQL数据库的BLOB中。另外,我有一个与网站一起运行的Windows应用程序。借助此应用程序,员工可以成功完成打孔并显示照片。图片是通过应用程序中的mysql查询(从非本地远程位置)检索的,该图片将图片内容转换为在图片框中输出的可读图片,从而确认了员工的身份。

I have a website that allows admins to upload employee pictures. For now, these pictures are stored in BLOB in my MySQL database. Also, I have a windows application that runs alongside the website. This application enables employees to punch in and have their pictures appear when they've successfully done so. The picture is retrieved via a mysql query within the application (from a non-local remote location) that converts the image content to a readable image that's being outputted in a picture box, confirming the identity of the employee.

在我看来,将图像存储在数据库中并通过简单的查询来检索图像要容易得多。我发现这比将图像路径存储在数据库中以及必须处理下载图像的应用程序要容易得多。我也不必处理冲突,文件夹组织和安全性以及由于x,y等原因而被重写的路径等问题。

In my eyes, it is much much easier to have the images stored in the database and have them retrieved via a simple query. I found this a lot easier than storing image paths in the database and having to deal with the application downloading the images. I also don't have to deal with collisions, folder organization and security and paths being re-written for x,y reasons, etc etc.

存储在DB裁剪到一定大小后仅20 kb。我的问题是,仍然值得用图像路径嵌入数据库,还是应该像现在这样简单地存储它们?如果在这种情况下仍不建议在数据库中存储图像,是否有正式的方法来存储图像路径?

The images stored in the DB are a mere 20 kb after being cropped to a certain size. My question is, is it still worth embedding the database with image paths or should they simply be stored as they are right now? If storing images in the database is still ill-advised in this case, is there a formal way to store image paths?

对此将提供任何帮助。如果这个问题不在这里,我将很乐意将其移动。

Any help on this would be greatly appreciated. If this question doesn't belong here, I'll be happy to move it.

推荐答案

如果图像是用户数据,而不是应用程序代码或主题的一部分,然后将图像存储在数据库中是个好主意,因为…

If the images are user data, rather than part of your application's code or theme, then storing the images in the database is a good idea, because…


  • 备份如果您只需要备份数据库,则更易于管理。另一方面,如果您将一些应用程序数据存储在数据库中,而将一些存储在文件系统中,则必须协调数据库和文件系统的备份计划,以确保两者的一致性。

  • Backups are easier to manage if all you have to back up is the database. On the other hand, if you store some application data in the database and some in the filesystem, then you'll have to coordinate the backup schedules of your database and your filesystem to ensure that the two are consistent.

如果您可以使用数据库管理员,那就太好了!您的备份应该已经做好了。如果没有,那么数据库备份的设置可能会有些棘手,但是一旦有了备份系统,它就会比文件系统备份更好。例如,许多数据库系统都支持流复制。

If you have a database administrator at your disposal, then great! Your backups should already be taken care of. If not, then database backups may be slightly tricky to set up, but once you do have a backup system, it can be better than filesystem backups. For example, many database systems have support for streaming replication.

文件系统还具有其优势,即性能和简单性,因为大多数Web服务器都是为服务静态文件而构建的。混合方法可以使您两全其美:

Of course, having the images on a filesystem also has its advantages, namely in performance and simplicity, since most webservers are built to serve static files. A hybrid approach could give you the best of both worlds:


  • 存储在数据库中的图像将是权威数据。

  • 您的应用程序可以具有将它们作为本地缓存中的文件提取为本地文件系统中的功能。该缓存不具有权威性,因此可以随时重建。

  • 然后,网络服务器可以直接从文件系统提供文件。

这篇关于将图像存储在数据库中而不是文件系统中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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