开发者

What is the best way to maintain integrity between each database record referring to an file path of an image on a disk?

开发者 https://www.devze.com 2023-02-14 10:10 出处:网络
I have a database. One of the contained tables will be used to save the file paths of images on a disk.

I have a database. One of the contained tables will be used to save the file paths of images on a disk.

The questio开发者_C百科n is

how to maintain the integrity between each record in the table and the corresponding image file on the disk?

I want to avoid the possibilities

  • a record with unavailable image file.
  • an image with no record in the table.


Your best strategy for maintaining integrity between the two is to eliminate the secondary storage route and store the file bits in the database directly. Most RDBMS have a binary data type that will store straight binary bits.

Have your application serialize/deserialize the bits to reconstitute the file contents as needed. Include a field for filename that includes the extension.


You are better off handling this in the Application code rather than adding integrity checks in Database.

You would want to add a two-way check: First before the data is uploaded into the database, make sure that the particular file exists. Second when the user retrieves the record throw an exception if the file does not exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消