What is the best way to associate a file with a piece of data?

前端 未结 8 998
别跟我提以往
别跟我提以往 2020-12-29 13:52

I have an application that creates records in a table (rocket science, I know). Users want to associate files (.doc, .xls, .pdf, etc...) to a single record in the table.

8条回答
  •  误落风尘
    2020-12-29 14:21

    Store the paths in the database. This keeps your database from bloating, and also allows you to separately back up the external files. You can also relocate them more easily; just move them to a new location and then UPDATE the database.

    One additional thing to keep in mind: In order to use most of the filetypes you mentioned, you'll end up having to:

    • Query the database to get the file contents in a blob
    • Write the blob data to a disk file
    • Launch an application to open/edit/whatever the file you just created
    • Read the file back in from disk to a blob
    • Update the database with the new content

    All that as opposed to:

    • Read the file path from the DB
    • Launch the app to open/edit/whatever the file

    I prefer the second set of steps, myself.

提交回复
热议问题