Saving images: files or blobs?

2020-01-27 05:09发布

When you save your images (supose you have lots of them) do you store then as blobs in your Database, or as files? Why?

Duplicate of: Storing Images in DB - Yea or Nay?

10条回答
混吃等死
2楼-- · 2020-01-27 06:01

I usually go with storing them as files, and store the path in the database. To me, it's a much easier and more natural approach than pushing them into the database as blobs.

One argument for storing them in the database: much easier to do full backups, but that depends on your needs. If you need to be able to easily take full snapshots of your database (including the images), then storing them as blobs in the database is probably the way to go. Otherwise you have to pair your database backup with a file backup, and somehow try to associate the two, so that if you have to do a restore, you know which pair to restore.

查看更多
冷血范
3楼-- · 2020-01-27 06:10

If I'm running on one web server and will only ever be running on one web server, I store them as files. If I'm running across multiple webheads, I put the reference instance of the image in a database BLOB and cache it as a file on the webheads.

查看更多
姐就是有狂的资本
4楼-- · 2020-01-27 06:10

Blobs can be heavy on the db/scripts, why not just store paths. The only reason we've ever used blobs is if it needs to be merge replicated or super tight security for assets (as in cant pull image unless logged in or something)

查看更多
太酷不给撩
5楼-- · 2020-01-27 06:14

Using file System is better as the basic feature you would be provided with while storing images as a blob would be 1. mutability which is not needed for an image as we won't be changing the binary data of images, we will be removing images as whole only 2. Indexed searching :which is not needed for image as the content of images can't be indexed and indexed searching searches the content of the BLOB.

Using file system is beneficial here because 1. its cheaper 2. Using CDN for fast access

hence one way forward could be to store the images as a file and provide its path in database

查看更多
登录 后发表回答