Creating Dynamic Media URLs with the getMediaURL.php File

fmMMS supports a number of different methods for including a Media file when sending an MMS message to your selected MMS Gateway. The Get Media Record URL method lets you generate a publicly accessible URL for a media file stored in a FileMaker container field, without having to first export and upload that to a web server.  This methods involves using the supplied getMediaURL.php file (versions for both the FileMaker Data API and the FileMaker PHP API are included) to generate a dynamic URL on the fly that the Gateway can use to download a media file from the container field in the Media table record. This requires the fmMMS file to be hosted on FileMaker Server.

N.B. the getMediaURL.php file currently doesn't work with FileMaker Cloud 2.x deployments due to the differences in how authentication is handled for FileMaker Cloud 2.x users with the Data API. We hope to have a version of the getMediaURL.php file that supports FileMaker Cloud 2.x soon.

The getMediaURL.php generates a URL that the Gateways can use to download the media file stored in the FileMaker container field in the Media table when sending a message. The URL that it generates uses the UUID value from the _kp_MediaID field in the Media table to create a URL that looks like the following:

https://web01.databuzz.com.au/Twilio/getMediaURL.php?id=16DFC88F-F2CE-4843-B2BB-F2A037EB915Q

Get Media Record URL Setup

To use the Get Media Record URL method and the supplied getMediaURL.php file you will first need to upload the getMediaURL.php file to a web server or your FileMaker Server to generate a URL that is publicly accessible. Follow the instructions for setting up Webhooks which explains where to store the php file and the requirements for the PHP API or the Data API.

You will need to replace the value for the $hostname variable in getMediaURL.php file with the IP address or DNS name of your FileMaker Server before you upload it.

Once you have the publicly accessible URL for the getMediaURL.php file you can enter this into your fmMMS account settings as follows:

1. Click on the  ACCOUNTS button at the top of the screen to view any existing fmMMS accounts and click the arrow button to the left to view the details for the selected Account (If you haven't already created an Account record in fmMMS click the New Account button on the toolbar and enter the details for your account with the MMS Gateway - see the Getting Started guide for further details).

2. For the Media Upload Method field select the Get Media Record URL option:

3. Click the gear icon button to the right to enter the URL to your getMediaURL.php file in the Media PHP File URL field:

You are now ready to test that the getMediaURL.php file is working successfully with your selected MMS Gateway. We recommend sending a test MMS to your mobile phone to ensure it is delivered successfully. When sending the MMS you just need to insert the file you wish to send into the Media container field like this:

When the Message has been sent a dynamic URL will be generated and stored in the URL field:

If you are having issues with sending Messages using the Get Media Record URL option and the getMediaURL.php file try copying the URL that was generated and pasting this into your web browser. This should display the media file you have inserted into the FileMaker container field to confirm the media can be successfully retrieved and that the getMediaURL.php file is working successfully. If there are any errors these should be displayed in the web browser as well and help you troubleshoot any issues with the getMediaURL.php file.

Note on using the FileMaker Data API and the getMediaURL.php file

For some MMS Gateways the getMediaURL.php file works differently between the PHP API version and the Data API version, due to the requirements of the MMS Gateway and how the FileMaker Data API returns files stored in container fields (it doesn't return the container field contents directly like the PHP API but instead returns a URL that you can use to retrieve the file stored in the container field, so we are unable to perform a redirect here for some MMS Gateways as they cache the original URL and won't follow the redirected URL. This means we are retrieving the file stored in the Media table container field and exporting that to the same directory on your server where the getMediaURL.php file is stored.

You will need to ensure the permissions on your server folder containing the getMediaURL.php file are set to allow read/write access to the folder - here's a screenshot showing how this might look if you're using an FTP application to upload the files to your server:

The Gateways that require the media file to be exported to the server folder containing the getMediaURL.php file are:

  • Twilio
  • Twilio API for WhatsApp
  • ClickSend
  • SignalWire

Deleting Exported Media

For MMS Gateways that require the media file to be exported you will need to manage the ongoing storage of these exported files to prevent them filling up your server etc. We have no setup any method to automatically delete these files but have provided a method to delete any of these exported files from within fmMMS.

You can use the supplied deleteMediaFile.php (upload this to your server in the same folder as the getMediaURL.php file) to delete any media files that you no longer require to be stored on your web server. In the Media table when viewing the Media Details there is a button in the top right hand corner - Delete Media on Web Server - which you can click to call the deleteMediaFile.php for the record you are viewing and delete the file on your server:

Once again make sure you set the permissions for the folder containing this file to have read/write access.

Still need help? Contact Us Contact Us