AnsweredAssumed Answered

Downloading PDF via web is broken

Question asked by dvaklyes on May 29, 2018
Latest reply on May 29, 2018 by dvaklyes

This weekend I did two major upgrades on our web site using the FileMaker API. First the web code was moved from a macOS 10.11 MacPro to an AWS Amazon Linux instance. And the FileMaker Server was upgraded from FMS 15 on macOS 10.11 to FMS 17 on macOS 10.13.4 .


All is working fine, except for the process to create and download custom PDFs generated in FileMaker.  A file with the right name gets downloaded, but it is empty. The file is generated with the MBS plugin and DynaPDF, and that still works. The plugin writes the file into a global container field on the record which is returned by the API.


Here is the relevant PHP code, which has worked for years:


$fm = new FileMaker($database_ConEd, $hostname_ConEd, $username_ConEd, $password_ConEd);

$request = $fm->newFindCommand('DownloadFiles');

$request->addFindCriterion('DF_FileCode', $SourceFile);

$request->setScript ('SERVER_Generate_Personalized_File', $ScriptParameter);

$result = $request->execute();

if (FileMaker::isError($result)) {die('<p>' . $result->getMessage() . ' (error ' . $result->code . ')</p>');}

$records = $result->getRecords();

$content = file_get_contents($records[0]->getFieldUnencoded('Test_Container')); <-- This is line 74

$length = strlen($content);

$filename = $OutputName . '_' . $records[0]->getField('DF_FileName').'.pdf';

header('Content-Description: File Transfer');

header('Content-Type: application/pdf');//<<<<

header('Content-Disposition: attachment; filename=' . $filename);

header('Content-Transfer-Encoding: binary');

header('Content-Length: ' . $length);

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Expires: 0');

header('Pragma: public');

echo $content;



As I said, the file gets downloaded with the correct name, but it is empty.

On the AWS web server, this PHP warning is recorded:


[Mon May 28 19:48:01.733794 2018] [:error] [pid 16948] [client xx.xx.xx.xx:58688] PHP Warning:  file_get_contents(https://FMS17Machine.domain/Streaming_SSL/MainDB/2C6D50F2CD82B4E817C4AE85CD15DEB7A42CD0234FAFB37988F30A7F6C36A553.pdf?RCType=EmbeddedRCFileProcessor): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized\r\n in /var/www/html/webServerRoot/ConEd/PersonalizePDFviaPlugin.php on line 74, referer:



I conversed with Christian yesterday and we confirmed that the MBS plugin is getting the PDF into the container field on the record. But it is not getting downloaded.


Any help would be greatly appreciated, including alternative methods for accomplishing the download.


Thanks in advance.