Reputation: 1835
How can an image stored in an embedded container field in a FileMaker Pro database be accessed via PHP and echoed to a native iOS application? There are several references to attaining the url, but nothing specifically about echoing the image as an encoded string.
Here are the steps in more detail:
As I have only worked with moving text back and forth between FileMaker Server and a native iOS app using similar methods, I am seeking guidance on doing the same for images, specifically for step #4.
Upvotes: 0
Views: 1424
Reputation: 616
I'm not sure which version of FileMaker you are using, or if you have access to the table structure, but if you do have access and you are using the latest version (version 13 as of this writing), you could create a calculation field that base64 encodes (Base64Encode function) the container field. I believe that you can decode base64 in Swift.
So, instead of placing the container field on the layout that PHP is accessing, place this calculation field on the layout. Then all you'll need to do in PHP is echo the base64 string, so that should take care of your steps 3, 4 & 5 together.
Hope that is of help!
Upvotes: 0
Reputation: 4892
While the article mentioned in the comments is a good start, the general solution has been to use a container bridge file from the FileMaker PHP API tutorial. I believe the tutorial files (an HTML file with folders for each lesson) is installed with FileMaker Server.
Regardless, Lesson 2 of the tutorial introduces the ContainerBridge.php file, which has the following contents (in a version which must obviously have an update somewhere):
<?php
/**
* FileMaker PHP Example
*
*
* Copyright 2006, FileMaker, Inc. All rights reserved.
* NOTE: Use of this source code is subject to the terms of the FileMaker
* Software License which accompanies the code. Your use of this source code
* signifies your agreement to such license terms and conditions. Except as
* expressly granted in the Software License, no other copyright, patent, or
* other intellectual property license or right is granted, either expressly or
* by implication, by FileMaker.
*
*/
//This is a bridge script that calls FileMaker::getContainerData with the provided url.
require_once("dbaccess.php");
if (isset($_GET['path'])){
$url = $_GET['path'];
$url = substr($url, 0, strpos($url, "?"));
$url = substr($url, strrpos($url, ".") + 1);
if($url == "jpg"){
header('Content-type: image/jpeg');
}
else if($url == "gif"){
header('Content-type: image/gif');
}
else{
header('Content-type: application/octet-stream');
}
echo $fm->getContainerData($_GET['path']);
}
?>
The idea is that the dbaccess.php
file creates the FileMaker object and sets up the URL, user name and password so that the $fm
object is correctly initiated. When you need to access the container data, you include this ContainerBridge.php file and use it as a URL.
echo '<img src="ContainerBridge.php?path=' . urlencode($record->getField('Image')) . '">';
Upvotes: 0