巴扎黑2017-04-18 10:38:51
There are at least two methods:
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
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
或tomcat
When 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.
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
来专门处理静态文件(图片,视频等)。
对于那些实在没办法静态化
的请求就由tomcat
For those requests that cannot be static
, they will be dynamically processed by tomcat
and sent back to the client.
大家讲道理2017-04-18 10:38:51
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