Skip to content

stevenwhitespacesystems/fm-mime-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

fm-mime-types

Returns a MIME-type string from a filename on the FileMaker Pro Platform.
Explore the docs »

Report Bug · Request Feature

FileMaker Version FileMaker Platform Commit Shield Contributors MIT License Facebook LinkedId

Table of Contents

About The Project

Logo

As we delved into the world of REST APIs using FileMaker, we stumbled across an issue.

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

When you are dealing with binary data and having to send HTTP Headers in relation to this data, you will most certainly have to provide a Content-Type header at some point.

This header tells the recipient the type of information that is being passed over the network.

e.g. A pdf file will have the Content-Type of application/pdf.

We found out during our development of fmapi-aws-s3 that to put data onto an S3 bucket, we would have to pass in the MIME-type of the file we send.

This was an issue and with any issue, solutions are born.

We present fm-mime-types.

A FileMaker script which when passed a valid filename, will return the correct MIME-type for that file format.

Built With

Features

  • Backwards Compatible: This script has been designed to be backwards compatibile to FileMaker Pro 12!

  • Small Code Base: We've optimised our code as much as possible which has resulted in the script being less than 50 script lines.

  • Extremely Fast: With optimisation comes efficiency. Our testings show that the script runs at less than 500ms on the first run. Subsequent runs after it's cached the mime-db.json run, consistently, at ~50ms. These tests where run on the script locally. Networked usage may differ.

  • No Dependencies: This script is fully dependent and requires no plugins.

Getting Started

Prerequisites

Version

The FileMaker script makes use of the Insert from URL script step introduced in FileMaker 12.

This means that this script will only work with FileMaker 12+ products.

Using the script with anything less than 12 will have unexpected behaviour.

Limitations

FileMaker Text Parsing Functions

We have built the rules for identifying MIME-types in FileMaker using all the Text Functions available to us and from our testing it has handled all the filenames thrown at it.

However, there may be some fringe cases where this breaks down. If you discover such a case, please create a Bug Report and we'll see if we can correct it. Unfortunately, there may be cases that can't be solved.

Usage

Installation

  1. Copy the fm-mime-types script to your solution.

It's that simple.

Quick Start

There are 2 fmp12 files provided here

  1. fm-mime-types.fmp12
  2. fm-mime-types-tests.fmp12

fm-mime-types.fmp12 file contains the script that you need to copy over.

fm-mime-types-tests.fmp12 file contains our test suite to confirm that the script behaves as intended.

If you open the fm-mime-types file, you can drag a file onto a container field or enter a filename manually and get the MIME-type by pressing the Get MIME-type button.

Sample MIME-types

filename MIME-type
test.pdf application/pdf
test.pdf.zip application/zip
test.js application/javascript
image.png image/png

Parameters

The parameters below can be used for the script. Each parameter has to be followed by a carriage return (¶). The table below will state it's position in the parameters list.

Position name Description
1 Filename This is a full filename of file you are trying to get a MIME-type of e.g. image.png
2 Object Name FileMaker 15 or less ONLY Insert From URL requires a field in FM < 16. Give a field on the current context an object name. This script is smart enough to set the field and then clear it out once it's done with it. Tip: Use a global field
3 Object Repetition FileMaker 15 or less ONLY Repitition number of Object Name value above. This parameter defaults to 1 so can be ignored if not required.

Here are 2 examples of what you'd pass the fm-mime-types script.

FileMaker <= 15

List (
  "image.png" ;
  "fm-mime-type-object" ;
  1
)

Where fm-mime-type-object is the object name of a field on the current layout.

FileMaker >= 16

"image.png"

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature)
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Steven McGill - WhiteSpace Systems Ltd - [email protected]

Project Link: fm-mime-types

Acknowledgements

fmapi Product Suite

When FileMaker 16 introduced cURL with the Insert from URL script step. Use cases for FileMaker Pro increased dramatically in relation to REST APIs.

It allowed developers to finally communicate with other web services and APIs without the need for 3rd party plugins. Integration with Couriers, Payment Gateways & Social Media Sites all became within touching distance.

However, without prior knowledge of cURL, HTTP Request Methods, HTTP Headers, JSON, OAuth Authentication, API Keys, API documentation etc, it can be extremely difficult to get started for the novice user or even the most proficient FileMaker developer.

And with that comes our goal, to simplify communications between your FileMaker App and the vast amount of Web Services available, no matter your ability level.

Read more over at What is fmapi?

fmapi Apps

A collection of FileMaker apps that communicate directly with popular 3rd party REST APIs.

  • fmapi-vies-vat - Integrate the EU Commissions Vies VAT API directly into you FileMaker App allowing you to validate EU VAT Numbers.

Releases

No releases published

Packages

No packages published