Store pictures as files or in the database for a web app?

后端 未结 10 1808
孤城傲影
孤城傲影 2020-11-22 06:32

My question is fairly generic and I know there might not be an 100% answer to it. I\'m building an ASP .NET web solution that will include a lot of pictures and hopefully a

相关标签:
10条回答
  • 2020-11-22 07:11

    Why not choose a individual NoSql database to store your files.

    It brings you with data integrity ,data consistency as @chburd mentioned.

    While you rdbms still keep small.

    0 讨论(0)
  • 2020-11-22 07:21

    Store the pictures on the file system and picture locations in the database.

    Why? Because...

    1. You will be able to serve the pictures as static files.
    2. No database access or application code will be required to fetch the pictures.
    3. The images could be served from a different server to improve performance.
    4. It will reduce database bottleneck.
    5. The database ultimately stores its data on the file system.
    6. Images can be easily cached when stored on the file system.
    0 讨论(0)
  • 2020-11-22 07:21

    Storing images in the database adds a DB overhead to serve single images and makes it hard to offload to alternate storage (S3, Akami) if you grow to that level. Storing them in the database makes it much easier to move your app to a different server since it's only the DB that needs to move now.

    Storing images on the disk makes it easy to offload to alternate storage, makes images static elements so you don't have to mess about with HTTP headers in your web app to make the images cacheable. The downside is if you ever move your app to a different server you need to remember to move the images too; something that's easily forgotten.

    0 讨论(0)
  • 2020-11-22 07:22
    1. Here is a step-by-step example (general approach, Spring implementation, Eclipse) of storing images in file system and holding their metadata in DB -- http://www.devmanuals.com/tutorials/java/spring/spring3/mvc/Spring3MVCImageUpload.html
    2. Here is an example too -- http://www.journaldev.com/2573/spring-mvc-file-upload-example-tutorial-single-and-multiple-files
    3. Also you can investigate a codebase of this project -- https://github.com/jdmr/fileUpload . Pay attention to this controller.
    0 讨论(0)
提交回复
热议问题