We got various cases where it would be useful to have a way to check the content of a file in FileMaker. Whether the file comes as hex or base64 encoded string, a container value or a file on disk. Why would be need this? Well, let's think about a few cases:
- You got a file without file extension and you need to know what it is.
- You got a JPEG, which actually is a PNG or HEIF image.
- Some user wanted to edit an image before uploading. They dropped it into a word document and later renamed it to have the extension to be imported.
- You like to check if an attachment is an executable as you like to prevent passing on malware.
To solve these problems, we got a few things in the past. Like we could try to load a picture in GraphicsMagick to see if it would load and thus likely be a real image. Or ask FileMaker to import a file and see if it passes. But to help you, we got three new functions for MBS FileMaker Plugin:
- Container.IdentifyData for container values
- Files.IdentifyData for files
- Text.IdentifyData for data in base64 or hex encoding
Whether you have a file to import, a container value in a field or from a function or some text encoded data from a web service, you can use one of these functions to look into the data. They will return one of the following texts:
PDF document. | |
---|---|
JPEG | JPEG image. |
GIF | GIF image. |
BMP | Windows BMP image |
WEBP | WebP image. |
PNG | PNG image. |
TIFF | TIFF image. |
GIF | GIF image. |
SVG | SVG image. |
ZIP | ZIP file, possible Office file |
HEIF | HEIF image file. |
FMP | FileMaker database. |
EXE | Windows executable |
MachO | macOS executable |
ELF | Linux executable |
You may combine them with other functions. e.g. if Container.IdentifyData returns "HEIF" for an image and you need a PNG, you would run it through Container.ReadImage to compare. Same for sending email attachments, where you could run the function and reject the attachment if it is an EXE, ELF or MachO file type.
Please note that docx and xlsx files from Word and Excel are internally zip files, so they get reported as zip file.
Please try it and let us know whether they work as expected.