As we delved into the world of REST APIs using FileMaker, we stumbled across a common challenge:

How do we get a file's MIME-type in FileMaker Pro?

Why MIME Types Matter

When you're dealing with binary data and sending HTTP headers, you'll almost certainly need to provide a Content-Type header at some point. This header tells the recipient the type of information being passed over the network.

For example, a PDF file has the Content-Type of application/pdf.

During our development of fmapi-aws-s3 (a FileMaker AWS S3 integration), we discovered that to upload data to an S3 bucket, we needed to include the MIME-type of the file being sent.

The Solution

We present fm-mime-types — a FileMaker script which, when passed a valid filename, returns the correct MIME-type for that file format.

How It Works

The script accepts a filename as its input parameter — for example, report.pdf or photo.png. It begins by extracting the file extension from the filename (the portion after the last full stop). This extension is then looked up against an internal mapping of file extensions to their corresponding MIME types.

The mapping covers a comprehensive range of common and less common file formats, spanning documents, images, audio, video, archives, and web-related file types. If the extension is found in the mapping, the script returns the corresponding MIME type string. If the extension is not recognised, the script returns application/octet-stream, which is the standard fallback MIME type for binary data of an unknown format.

The entire lookup is handled within FileMaker's native scripting engine, so there are no external dependencies, plugins, or API calls involved.

Common MIME Types

The following table illustrates some of the most frequently used MIME types that fm-mime-types can return:

  • .pdfapplication/pdf
  • .pngimage/png
  • .jpg / .jpegimage/jpeg
  • .csvtext/csv
  • .jsonapplication/json
  • .xmlapplication/xml
  • .zipapplication/zip
  • .htmltext/html
  • .txttext/plain
  • .docapplication/msword
  • .xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet

The script supports many more formats beyond this list. For the full mapping, refer to the source code on GitHub.

Installation

To get started, download the script from the GitHub repository. Import it into your FileMaker solution using the Import Scripts option in the script workspace. To use the script, call it with a filename as the script parameter and retrieve the result using Get ( ScriptResult ).

Use Cases

MIME types are fundamental to modern web and API interactions. Here are some common scenarios where fm-mime-types proves invaluable:

  • Setting Content-Type headers for REST API calls — When sending files or data via Insert from URL or other HTTP methods in FileMaker, you typically need to specify the Content-Type header. fm-mime-types provides the correct value automatically based on the filename.
  • Uploading files to S3 and cloud storage — Cloud storage services such as AWS S3, Google Cloud Storage, and Azure Blob Storage require the MIME type when uploading objects. This script ensures the correct type is provided, which in turn ensures the file is served with the proper headers when downloaded.
  • Building email attachments — When constructing multipart email messages programmatically, each attachment must declare its MIME type. fm-mime-types takes the guesswork out of this process.
  • Validating file types — Before processing an uploaded file, you may wish to verify that its extension corresponds to an expected MIME type. This script provides a simple way to perform that validation within your FileMaker logic.

Requirements

fm-mime-types requires FileMaker Pro 16 or later. Whilst the script does not strictly depend on JSON functions, it was designed alongside our other tools (fm-csv2json and fm-xml2json) and follows the same conventions. The script runs entirely within FileMaker's native scripting engine, requires no plugins, and is fully compatible with FileMaker Server and FileMaker Cloud.

Download

The script is available to download free of charge on GitHub.

Building FileMaker integrations with cloud services? We specialise in connecting FileMaker to the wider web.

Book a Free Consultation