Working with Images and Files from Container Fields

When you request data from a FileMaker container field, you don't get the file itself. Instead, the Data API provides a special, secure URL that points to the file.

This guide will help you solve the most common problem developers face when trying to use these URLs.


The Problem: "Why Won't My Image Display?"

By default, your FileMaker Server is configured for maximum security. This means the URL provided for a container field is private and temporary. It is locked to the specific, secure session your server-side code used to request it.

Because of this, you cannot simply take this URL and place it in a standard HTML <img> tag. The user's browser does not have the required security token to access the private URL, so the image will appear broken.


The Solution: Enable Public Container URLs

To display an image in an <img> tag or provide a direct link to a file, you must change a setting on your FileMaker Server. This change tells the server to generate temporary public URLs instead of private ones.

How to Change the Setting

You must run the following command in the command-line interface on your FileMaker Server:

fmsadmin set serverprefs AuthenticatedStream=2

After running this command, any new container URLs generated by the Data API will be public.

Important Note on Expiration: Even though the URL is now public, it is still temporary and will expire after a short period. It is not a permanent link. This is an important consideration for page caching, as a cached page may contain an expired URL. You may need to adjust your caching strategy for pages that display this temporary data.


Alternative Ways to Display Images

While using the public container URL is often the most direct method, there are other robust techniques for displaying container images that do not rely on it. These methods avoid the issue of expiring URLs, which simplifies page caching and prevents broken images on cached pages. However, you will still need to consider your caching strategy for how and when the images themselves are updated.

Option 1: Use Base64 Encoding

This method involves converting the image into text directly within FileMaker, retrieving that text, and embedding it into the HTML.

  1. In FileMaker: Create a new Calculation field in your table. The calculation should be Base64Encode(YourContainerField). Set the result type to "Text". This field will now contain the Base64-encoded version of your image.

  2. In Your Snippet: Use the Data API to get the text from this new calculation field.

  3. In Your HTML: Use a "Data URI" in your <img> tag to display the image, like so:

    <img src="data:image/jpeg;base64,<?php echo $base64_data_from_filemaker; ?>">

This method embeds the image data directly into the HTML, avoiding any extra server requests or URL expiration issues.

Option 2: Upload Image to Your Web Server

For images that don't change often, you can upload them directly to your WordPress server and link to them normally. You can create a CWP Snippet that acts as an endpoint, allowing FileMaker to push images to your server.

The process works like this:

  1. A PHP snippet is created in CWP Snippets to accept file uploads.
  2. In FileMaker, a script uses the Insert from URL script step to post the container data to the PHP snippet's URL.
  3. The PHP snippet saves the file to the wp-content/uploads directory.
  4. Your application can then refer to the image using its permanent URL on your website.

A pre-built add-on that provides this endpoint functionality will be available as a free download from the CWP Snippets website soon.