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

查看:31
本文介绍了上传图片、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天全站免登陆