It is stored in the database as you mentioned, but 没听过也没见过谁真这么干过. The reasons for not doing this are at least the following two points:
For example, a picture is about 1M. If there are too many, the size of the database file will expand rapidly
The volume of data is large, and it will be very slow to load when querying
Method 2
The file is placed on the disk like an ordinary file, and the path of the file in the file system is recorded in the database. 磁盘上,数据库中记录文件在文件系统中的路径。 读取文件的时候,先从数据库读取文件在磁盘上的位置,然后服务器(nginx或tomcatWhen reading a file, first read the file's location on the disk from the database, and then the server (nginx or tomcat, etc.) will send the file back to the client.
A little further:
For method two, the files are often placed on a dedicated static file server to do 动静分离,感兴趣的话可以搜搜关键字:nginx反向代理.
For example, you can use nginx or apache to specifically process static files (pictures, videos, etc.). nginx或apache来专门处理静态文件(图片,视频等)。 对于那些实在没办法静态化的请求就由tomcatFor those requests that cannot be static, they will be dynamically processed by tomcat and sent back to the client.
There are at least two methods:
Method 1
It is stored in the database as you mentioned, but
没听过也没见过谁真这么干过
.The reasons for not doing this are at least the following two points:
For example, a picture is about 1M. If there are too many, the size of the database file will expand rapidly
The volume of data is large, and it will be very slow to load when querying
Method 2
The file is placed on the
disk
like an ordinary file, and thepath
of the file in the file system is recorded in the database.磁盘
上,数据库中记录文件在文件系统中的路径
。读取文件的时候,先从数据库读取文件在磁盘上的位置,然后服务器(
nginx
或tomcat
When reading a file, first read the file's location on the disk from the database, and then the server (nginx
ortomcat
, etc.) will send the file back to the client.A little further:
For method two, the files are often placed on a dedicated static file server to do
动静分离
,感兴趣的话可以搜搜关键字:nginx反向代理
.For example, you can use
nginx
orapache
to specifically process static files (pictures, videos, etc.).nginx
或apache
来专门处理静态文件(图片,视频等)。对于那些实在没办法
静态化
的请求就由tomcat
For those requests that cannot bestatic
, they will be dynamically processed bytomcat
and sent back to the client.Save it on your own server and do your own distributed storage of files, high availability and so on
Call third-party interfaces, such as Paiyun or Alibaba Cloud OSS, without having to operate and maintain it yourself