Returns a MIME-type string from a filename on the FileMaker Pro Platform.
Explore the docs »
Report Bug
·
Request Feature
- About the Project
- Features
- Getting Started
- Usage
- Contributing
- License
- Contact
- Acknowledgements
- fmapi Product Suite
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.
- FileMaker Pro
- No 3rd party plugins.
-
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.
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.
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.
- Copy the
fm-mime-types
script to your solution.
It's that simple.
There are 2 fmp12 files provided here
- fm-mime-types.fmp12
- 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.
filename | MIME-type |
---|---|
test.pdf |
application/pdf |
test.pdf.zip |
application/zip |
test.js |
application/javascript |
image.png |
image/png |
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.
List (
"image.png" ;
"fm-mime-type-object" ;
1
)
Where fm-mime-type-object
is the object name of a field on the current layout.
"image.png"
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Steven McGill - WhiteSpace Systems Ltd - [email protected]
Project Link: fm-mime-types
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?
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.