存储上传的图像:它应该存储在服务器上还是存储在数据库中? [英] Storing uploaded images: Should it be stored on the server or in the database?

查看:1047
本文介绍了存储上传的图像:它应该存储在服务器上还是存储在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力翻新一个非常古老的基于Java Servlet的webapp。 webapp允许用户上传图像。 webapp存储数据库中图像的路径引用,但是将图像上传到它们所在的服务器上的目录。

I've been working on renovating a very old Java Servlet based webapp. The webapp lets users upload images. The webapp stores a path reference to the images in the database, but uploads the images to a directory on the server where they stay.

webapp的数据库已升级到我被告知Oracle 11g可以处理二进制信息。

The database for the webapp was upgraded to Oracle 11g which I am told can handle binary information.

所以,我的问题是,哪个更聪明?

So, my question is, which is the smarter thing to do?

继续将图像作为文件存储在服务器上或将图像填充到Oracle 11g数据库中吗?

Stay with storing the images as files on the server or stuff the images into the Oracle 11g database?

非常感谢提前

Steve

推荐答案

是的,您可以在Oracle中使用BLOB作为二进制数据。 (以及许多其他数据库。)我们在这里使用它们来存储PDF文件。

Yes, you can use BLOBs for binary data in Oracle. (And many other databases.) We use them here to store PDF files.

我已经看到它完成了两种方式。将图像存储在数据库中,或将图像存储在文件系统中,然后将文件名保存在数据库中。

I've seen it done either / both ways. Store the images in the database, or store the images in the file system and then save the file name in the database.

存储在数据库中的优点

数据库中就可以了。你拉出一条记录,相关的图像就在那里。

It's all right there in the database. You pull out a record, the associated image is right there with it.

您可以在文件及其相关数据之间获得数据完整性(当然,假设一个良好的模式设计。)

You get data integrity between the file and its associated data (assumes a good schema design, of course.)

获取数据和图像的一种逻辑操作。

One logical operation to get data and image.

我发现扩展数据库以保存大量二进制数据比使用文件系统更难,更加昂贵。

I find it harder and more expensive to scale a database to hold a lot of binary data than the file system alternative.

存储在数据库中的缺点

并非所有工具都可以轻松浏览图像。

Not all tools will make it easy to browse the images.

无法轻松访问网络上的图片。

Can't easily access the images from the web.

根据文件大小和数量,您最终可能会获得大量原始图片某些表中的数据。

Depending on file size and quantity, you can end up with a lot of raw data in some of your tables.

加载和存储blob数据并不总是直截了当。 (我最近为Hibernate写了一个自定义数据类型,例如,处理我们的blob PDF。)

Loading and storing blob data isn't always straight forward. (I recently wrote a custom data type for Hibernate, for example, to handle our blobbed PDFs.)

文件系统的优点

读取和写入文件的效率可能更高。

Probably more efficient for reading and writing the files.

如果您想在网络上提供图像,可以直接从文件系统中执行此操作。

If you want to serve the image up on the web, you can do that right from the file system.

在调试过程中更容易浏览图像,还有许多免费工具可以做到这一点。

Easier to browse images during debugging, and lots of free tools to do this.

我认为在将Blob放入文件系统时更容易扩展应用程序。

I believe it to be easier to scale an application when putting blobs in the file system.

文件系统的缺点

数据完整性/一致性问题。更改一些有关文件结构的内容,您还需要在数据库中执行另一个步骤。

Data integrity / consistency issues. Change something about the file structure, and you have another step to do in the database.

备份是另一回事。

多个逻辑操作(从数据库读取,从文件系统读取)以获取图像和数据。

Multiple logical operations (read from database, read from file system) to obtain image and data.

这篇关于存储上传的图像:它应该存储在服务器上还是存储在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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