search

Home  >  Q&A  >  body text

java - 关于图片,视频等保存数据库的问题,谢谢

1.以前我咨询过一些前辈,他们说将图片和视频以文件形式保存在服务器上比较好(一般会腾出一台专门放上传文件的服务器),因为数据库写入写出太消耗资源。

2.那我想问下如果有一天用户突然要迁移项目到另一台服务器,比如原来的服务器,图片都是存放在D://pic//目录下,然而新的服务器没有D://盘符怎么办?

高洛峰高洛峰2886 days ago484

reply all(6)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:45:55

    The database generally stores the path of resources. Relative paths are generally used in projects. Absolute paths should be rarely used. If you use relative paths, there will be basically no problems with project migration.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:45:55

    Image and video resources are placed on separate servers and accessed using separate domain names, such as img.xxx.com, so migrating the server will not affect it. Even if the path changes, it can be rewritten with rewrite.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:45:55

    It must be a separate server. The database stores links. If the value of a certain field in the database is too large, it will affect the query efficiency of the entire table.

    reply
    0
  • PHPz

    PHPz2017-04-17 17:45:55

    1. As long as the directory structure does not change, it should be easy to change the path;
    2. For pictures that are accessed frequently and can be made public, it is recommended to use storage services such as Qiniu. This will reduce server pressure on the one hand, and after CDN, access Faster too.

    reply
    0
  • 阿神

    阿神2017-04-17 17:45:55

    When I was studying database principles in school, the teacher repeatedly asked this question. I didn’t understand it at the time. Later, when I took JSP/Servlet as an elective, the teacher put everything he got into the database, and then I was confused. . .

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:45:55

    The path to store files in the database should not use absolute paths,

    reply
    0
  • Cancelreply