KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using Blobs to Store Files that Need to Be Installed on the System
PRODUCT: 4D | VERSION: 2003 | PLATFORM: Mac & Win
Published On: June 3, 2004
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

From time to time, your database applications may require certain files to be placed in certain directories. Such files can include preference files, Perl scripts or Applescript files, among others. One way to make sure that the files are found in the correct location is to store the files as blobs in a table and have your 4D application create the files when starting up for the first time. Below is a quick example of both reading in the file as a blob and writing out the blob to a file.

`Store the file as a blob variable
ON ERR CALL("Doc_Exist")
$docref:=Open document($path)
ON ERR CALL("")

If (OK=1)
    CLOSE DOCUMENT($docref)
    DOCUMENT TO BLOB(Document;$blob)
End if


`Write out the blob into a file. The variable $file contains the absolute path.
$docref:=Create document($file)
If (OK=1)
    CLOSE DOCUMENT($docref)
    BLOB TO DOCUMENT($file;[[Table]Blob_Field)
End if