The A–Z of FileMaker: C

C is for container

Container is a field type.

When you build a database, most of your fields will likely be text fields. Other standard data field types are number, date, time and timestamp. Although each of these have subtleties in how they store and present data, they are fairly obvious in their usage.

Why use container fields?

Container fields exist to store files such as a picture, a video or a PDF file. Such files are often referred to as binary files (as opposed to text files). Although some of their contents may be read as text, the file usually requires interpretation to ‘read’ the contents.

As opposed to storing data such as a text string or a number, container fields allow us to store documents or files. This can be extremely useful in creating a store of files that can be searched and accessed within a database structure. Many people will find use for a document management solution that stores PDF copies of files.

Inserting

There are a few different ways you can use to get a file into a container field and container fields have additional native functionality on iOS devices.

On the desktop, you can insert a picture into a container by:

  • drag and drop
  • Insert > Picture…
  • Insert > File…

Either of the first two methods will display the picture in the container field; the last method will display only the file icon and name. Your choice will depend on your intended use of the file – most users will be storing pictures for viewing while using the database.

On iPhone and iPad devices, you can insert images directly from the camera or from the Photo Library. Container fields also allow you to scan and capture a bar code with the camera, or to capture a signature as an image using sign-on-glass.

PDF files can be stored and displayed such that they are interactive – you can scroll through a multi-page PDF in a container field and use tools to zoom and print. To do this, the PDF must be drag-dropped into the container )or use Insert > PDF…), and the container must be formatted on the layout to be interactive (see later section on Formatting).

Storage

By default, files are copied into a container field and stored in the database file itself. This has two implications:

  • the original file can be moved, edited, renamed or deleted without affecting the stored copy
  • the database file will get larger, by approximately the size of the file inserted

When using the Insert menu to insert a picture, file, media or PDF, there is an option in the dialog to “Store only a reference to the file”. If you check this option, FileMaker will create a link to the original file in the container field. This will keep the database file size smaller. The link is used when the container field is displayed. If the file linked is missing, an error is shown in the container field – “The file cannot be found: <file name>”. This could happen if the file was moved or renamed.

Container fields have special field options under Storage.

You can change the option to store container data externally. This means that all files are stored outside of the database file in a folder structure created and managed by the FileMaker client. The folder structure is usually next to the database file in the computer filing system (there are special locations on FileMaker Server for hosted files).

For external storage, there is a further option for secure storage  or open storage. Secure storage creates a complex filing structure based on UUIDs and also encrypts the files. Files can only be decrypted by the FileMaker client and the FileMaker database. Open storage creates a logical filing structure of file/table/field with the raw files inside.

If any externally stored file is altered, the container file will display an error that the file has been tampered with (see above image). This is a security feature.

Formatting

Container fields on a layout can be formatted through Data Formatting on the Data tab of the Inspector (see below). These formatting options affect the size of the image displayed, alignment in the container, and whether the container field instance is interactive (important for PDF display and video playback).

Export

If the user has access to the field, they can export the contents of a container field using Edit > Export Field Contents….

Calculations

There are some calculations which are useful when looking at container field contents. Calculations can be used to get information about the file in a container field.

GetContainerAttribute ( Table::Container; "all" )

returns a return-separated list of a lot of useful attributes of an image such as file name, storage type and file size. The attributes are grouped into categories and have name pairs. Use parsing techniques to extract any attribute data you need. An example of what is returned is shown here:

[General] 
Filename: chart-1.png 
Storage Type: File Reference 
MD5: 00AE673591301E56D2EDFDFC53D21280 
File Size: 2355 
Internal Size: 74 
External Size: 2355 
External Files: 1

You can also query a single attribute, so:

GetContainerAttribute ( Table::Container; "filename" )

will return just the named attribute. The file name can also be extracted using:

GetAsText ( Table::Container )

Where the file is stored as a reference, the above expression will return the file name and the stored file path as a return separated list. For example:

file:landscape.png
filemac:/Macintosh HD/Users/johndoe/Desktop/landscape.png

Another GetContainerAttribute is filesize, the file size in bytes, which can also be returned using:

Length ( Table::Container)

For photos, you can access metadata if it is stored in the file. This may include latitude and longitude of the photo location, and make and model of the camera.

For signatures captured on an iOS device, use the signed attribute to get the timestamp when the signature was inserted.

The GetThumbnail function is very useful to return a down sampled version of an image stored in a container field (calculation result is container). The function format is:

GetThumbnail ( sourceField ; fitToWidth ; fitToHeight )

This example will return an image one third the size of the original:

GetThumbnail ( picField ; 
               GetWidth ( picField ) / 3 ; 
               GetHeight ( picField ) / 3 )
Want to know more?

uLearnIT runs FileMaker training classes in Australia and New Zealand. See the FileMaker Training page for more details.

(Visited 1 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *