什么是存储上传的图像,SQL数据库或磁盘文件系统的最佳地点? [英] What is the best place for storing uploaded images, SQL database or disk file system?

查看:259
本文介绍了什么是存储上传的图像,SQL数据库或磁盘文件系统的最佳地点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,允许用户将图像上传到服务器。我期望每天大约20图像所有jpeg和可能未编辑/调整大小。 (这是另一个问题,如何在存储前调整服务器端的图像大小。也许有人可以请在评论中删除一个.NET资源)。
现在我想知道存储上传图片的最佳位置是什么。

I'm writing an application that allows users to upload images onto the server. I expect about 20 images per day all jpeg and probably not edited/resized. (This is another question, how to resize the images on the server side before storing. Maybe someone can please drop a .NET resource for that in the comment or so). I wonder now what the best place for storing uploaded images is.


  • 将图片作为文件存储在

  • Store the images as a file in the file system and create a record in a table with the exact path to that image.

或者,使用图片将图片本身存储在表格中数据库服务器的二进制数据数据类型。

Or, store the image itself in a table using an "image" or "binary data" data type of the database server.

我看到两者的优点和缺点。
我喜欢a),因为我可以轻松地重新定位文件,只需要更改表项。另一方面,我不喜欢在Web服务器上存储业务数据,我不真的想将Web服务器连接到任何其他数据源保存业务数据(出于安全原因)
我喜欢b)因为所有信息都在一个地方,可以通过查询轻松访问。另一方面,数据库很快就会变得非常大。外包数据可能更困难。

I see advantages and disadvantages in both. I like a) because I can easily relocate the files and just have to change the table entry. On the other hand I don't like storing business data on the web server and I don't really want to connect the web server to any other datasource that holds business data (for security reasons) I like b) because all the information is in one place and easily accessible by a query. On the other hand the database will get very big very soon. Outsourcing that data could be more difficult.

推荐答案

我通常将文件存储在文件系统上,虽然有例外。对于文件,文件系统是最灵活和高效的解决方案(通常)。

I generally store files on the file-system, since that's what its there for, though there are exceptions. For files, the file-system is the most flexible and performant solution (usually).

在数据库上存储文件有一些问题 - 文件通常更大比您的平均行 - 包含许多大文件的结果集将消耗大量的内存。此外,如果您使用采用表锁的存储引擎(例如,ISAM),您的文件表可能会被锁定,具体取决于您存储的文件的大小/速率。

There are a few problems with storing files on a database - files are generally much larger than your average row - result-sets containing many large files will consume a lot of memory. Also, if you use a storage engine that employs table-locks for writes (ISAM for example), your files table might be locked often depending on the size / rate of files you are storing there.

关于安全性 - 我通常将文件存储在文档根目录以外的目录中(无法通过http请求访问),并通过脚本正确授权。

Regarding security - I usually store the files in a directory that is outside of the document root (not accessible through an http request) and serve them through a script that checks for the proper authorization first.

这篇关于什么是存储上传的图像,SQL数据库或磁盘文件系统的最佳地点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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