哪种是在服务器上存储文件(在数据库中或单独存储位置)的最佳方法? [英] Which is the best method to store files on the server (in database or storing the location alone)?

查看:1168
本文介绍了哪种是在服务器上存储文件(在数据库中或单独存储位置)的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中(类似 mediafire rapidshare ),客户端可以将文件上传到服务器。我使用 DB2数据库 IBM WAS Web服务器 JSP作为服务器端脚本。我创建了我自己的加密算法,因为它是项目的主要目标。

In my project (similar to mediafire and rapidshare), clients can upload files to the server. I am using DB2 database and IBM WAS web server and JSP as server side scripting. I am creating my own encryption algorithm, as it is the main aim of the project.

我需要建议文件本身是应该存储在数据库还是只有位置的文件应存储。哪种方法最好?

I need suggestion whether files themselves should be stored in the database or if only the location of the files should be stored. Which approach is best?

推荐答案

在数据库中存储BLOB有优点和缺点。

There are Pros and Cons for storing BLOBs in the database.


  • DBMS对BLOB的支持非常好

  • 对BLOB的JDBC驱动程序支持非常好

  • 在事务中可能会发生对文档的访问。无需担心手动清理或家政。如果该行被删除,BLOB数据也是如此。

  • 不必担心文件系统限制。文件系统通常不能很好地将一百万个文件存储在单个目录中。您必须在多个目录中分发文件。

  • 所有内容都备份在一起。如果你采取数据库备份,你有一切,没有必要担心额外的文件系统备份(但见下文)。

  • 可以通过SQL轻松访问(没有FTP或其他工具)。这种访问已经存在并受到控制。

  • 与其余数据相同的访问控制。无需设置操作系统用户组即可限制对BLOB文件的访问。

  • DBMS support for BLOBs is very good nowadays
  • JDBC driver support for BLOBs is very good
  • access to the "documents" can happen inside a transaction. No need to worry about manual cleanup or "housekeeping". If the row is deleted, so is the BLOB data
  • Don't have to worry about filesystem limits. Filesystems are typically not very good at storing million of files in a single directory. You will have to distribute your files across several directories.
  • Everything is backed up together. If you take a database backup you have everything, no need to worry about an additional filesystem backup (but see below)
  • Easily accessible through SQL (no FTP or other tools necessary). That access is already there and under control.
  • Same access controls as for the rest of the data. No need to set up OS user groups to limit access to the BLOB files.

  • 无法直接从操作系统访问(如果您需要使用命令行工具处理文件,则会出现问题)

  • 无法通过(可能是性能问题)

  • 数据库备份(和还原)更复杂(因为大小)。增量备份通常在文件系统中更有效

  • DBMS缓存注意事项

  • 不适合高写情况

  • Not accessible from the OS directly (problem if you need to manipulate the files using commandline tools)
  • Cannot be served by e.g. a webserver directly (that could be performance problem)
  • Database backup (and restore) is more complicated (because of size). Incremental backups are usually more efficient in the filesystem
  • DBMS cache considerations
  • Not suited for high-write scenarios

你需要自己判断哪个优势和哪个劣势对你更重要。

You need to judge for yourself which advantage and which disadvantage is more important for you.

我不同意一个广泛的假设,即在数据库中存储BLOB总是一个坏主意。这取决于 - 许多其他决定。

I don't share the wide-spread assumption that storing BLOBs in a database is always a bad idea. It depends - as with many other decisions.

这篇关于哪种是在服务器上存储文件(在数据库中或单独存储位置)的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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