Change Containers from Files to Interactive Content in an Instant

By Daniel Wood, 21 April 2015

File versus Interactive

If you are wondering what we are meaning when we talk about files and interactive content it is rather simple. There are two ways in which data can be stored in a container. The first is simply as a file. This is done using the "Insert File" option or script step (without interactive settings chosen).

Items inserted into containers as files are unable to be used as interactive content, and they display as an icon and filename only.  In the past before FileMaker 12 this was the primary method of inserting items into containers, and when it comes to older solutions you will find most have files stored in this manner.

FileMaker 12 introduced interactive containers - a means to make container data more "interactive" funnily enough. It gave the ability to scroll PDF documents, listen to and stream both audio and video direct from containers (and the server).  The problem with this new method of container display was that it did not play ball nicely with container data that was inserted as a file.  Interactive containers on layouts were unable to detect the type of file in a container whose contents was added as a file, and so contents could not be rendered interactively. Below is an example of what a container looks like with a file inserted.

What a container with a file in it looks like

How do we make use of Interactive Containers?

This dilemma arose primarily out of the fact interactive containers can nicely render PDF documents that can be scrolled, opened in preview, printed and saved.  We wanted to use this new feature, but all our existing client solutions prior to FileMaker 12 had their PDF documents inserted as files, and as such were not compatible with interactive containers.

Our initial methods for making the fix were rather crude and involved writing scripts that would loop through records, exporting container contents to the temporary folder on disk, and then re-importing that back into the same container, albeit this time as a PDF, such that it could be displayed interactively.

The process was tedious and time consuming, not to mention hard to setup for multiple containers on a large solution!

    

Introduce Stephen the Bright Spark!

Recently our most experienced developer Stephen was musing over this very issue for one of his clients solutions that house literally thousands and thousands of PDF's, which by the way are all hosted on remote volumes.

How could he display these PDF's as interactive content, without the hassle of exporting and re-importing? and then it hit him!

Actually, we're not quite sure how it hit him, but it's a little bit of luck, combined with a little stroke of genius, and he cracked it!

   

Base64 Encoding and Decoding is the key!

Stephen tested and showed that if you use FileMaker 13's Base64Encode and Base64Decode functions, you can convert container data into interactive container data, here's how it works:

Base64Decode ( Base64Encode ( Container ) ; Filename )

That's it!  He realised that the encode function simply encodes data with no knowledge of its file type.  The decode function however requires you to specify a filename with extension. This is the key thing, decode function will turn the encoded text back into a file of the nominated stream depending on the extension you choose.  All you need to do is make sure the filename is the same as the original files name and you're all set!

In fact if we look at the definition for Base64Decode we see:

Base64Decode ( text {; filenameWithExtension } )

It explicitly requires an extension for this very purpose.

   

Putting it to use

There are a number of ways to make use of this. in Stephens case, he wanted to keep the files exactly as they were untouched so did not replace the container data. However he created an unstored calculation on the table with the container, and set it to the above function. He now had a calculation that can render the container as interactive content that he could use on layouts where needed.

You can also write a very simple replace script that can update all container data in a single step.

The example file attached below illustrates this. Here we have abstracted it all into a single custom function called "Interactivate" that is passed a container as a parameter. The output of this is the container data turned into interactive content.  Simply run this function over any container you want to update to interactive content.

   

Example File

Please find attached an example file. This file is provided to help you fully understand what is going on in the rest of the article above. Note that FileMaker 13 is required to view this example file as it uses FileMaker 13 specific functions.

Click here to Download the Example File

Something to say? Post a comment...

Comments

  • Eldad 16/05/2015 5:43pm (10 years ago)

    Beautiful!

  • Robert Moran 13/05/2015 1:07pm (10 years ago)

    Stellar!!

  • Kevin Frank 09/05/2015 4:45am (10 years ago)

    Another revelation. Thank you, Daniel & company, for once again pushing the envelope and writing it up so clearly.

  • Stephen Wonfor 22/04/2015 6:58am (10 years ago)

    Amazing, what an insight!

  • Gale 22/04/2015 12:06am (10 years ago)

    This is absolutely brilliant.

  • Jeroen Aarts 21/04/2015 10:18pm (10 years ago)

    Absolutely fantastic! Our developer Jan already discovered a method to dynamically rename container files using exactly the same technique. I allow myself to post a link to it :-) http://bit.ly/fm-rename-containers

RSS feed for comments on this page | RSS feed for all comments

Categories(show all)

Subscribe

Tags