Search code examples
phpcoldfusioncoldfusion-10coldfusion-11lucee

PHP to Coldfusion zip/pkpass output stream


This project is apple wallet project I have but in PHP code im facing challenges not much help is available around my PHP question are open no response so far anyway now I decided to convert in coldfusion.

Im able to save ZIP/PKPASS file in binary in BLOB. When im sending PHP API GET Request to fetch card(binary zip/pkpass) it is returning me binary stream see attach screen below. enter image description here

same result I want to achieve in coldfusion when I'm sending request to coldfusion API code also attached below.

POSTMAN: enter image description here

Firefox: enter image description here

im trying to convert PHP code in coldfusion(lucee). Binary code in database which is zip file but extension is '.pkpass',database field name is "data".

when im running coldfusion code it is giving error "Corrupted Content Error".

PHP code :

 $myPass = $result->fetch();

        $data = $myPass['data']; //zip/pkpass file Binary code from DB
        $nameFile = 'passbook_'.time().'.pkpass';
        file_put_contents($nameFile, $data);

        $stream = function () use ($nameFile) {
            readfile($nameFile);
        };

        return $app->stream($stream, 200, array(

            'Pragma' =>  'no-cache',
            'Cache-Control' => 'private,false',
            'Content-Transfer-Encoding' =>  'binary',
            'Content-Disposition' => 'inline; filename="'.basename($nameFile).'"',
            'Content-Type' => 'application/vnd.apple.pkpass',
            'Content-length' => filesize($nameFile),
            'Content-Disposition' => 'attachment; filename="'.$nameFile.'"',
            'Last-Modified' => gmdate('D, d M Y H:i:s T')
        ));

Coldfusion Code : NOT WORKING Need assistance

   <cfset filename = getPass.serial_number&'_'&createUUID()&'.pkpass'>  
            <cfheader name="Pragma" value="no-cache">
            <cfheader name="Cache-Control" value="private,false">
            <cfheader name="Content-Transfer-Encoding" value="binary">
            <cfheader name="Content-Disposition" value="inline; filename=#filename#">
            <cfheader name="Content-Type" value="'application/vnd.apple.pkpass">
            <cfheader name="Content-Disposition" value="attachment; filename=#filename#">
            <cfheader name="Content-Disposition" value="#DateFormat(getPass.updated_at, "yyyy-mm-dd")#' '#TimeFormat(getPass.updated_at, 'hh:mm:ss')#">
<cfcontent type="application/x-zip-compressed" variable="#BinaryDecode(getPass.data, 'Base64')#"> <!--- Binary Data from db 'getPass.data' --->

Solution

  • The main problem seems to be that you're putting the last modified value in a "Content-Disposition" header. Try fixing that and cleaning up the other headers as follows:

    <cfscript>
    filename = "#getPass.serial_number#_#CreateUUID()#.pkpass";
    cfheader( name="Pragma", value="no-cache" );
    cfheader( name="Cache-Control", value="private,false" );
    cfheader( name="Last-Modified", value="#DateFormat( getPass.updated_at, 'yyyy-mm-dd' )# #TimeFormat( getPass.updated_at, 'hh:mm:ss' )#" );
    cfheader( name="Content-Transfer-Encoding", value="binary" );
    cfheader( name="Content-Disposition", value="attachment; filename=#filename#" );
    cfcontent( variable="#getPass.data#", type="application/vnd.apple.pkpass" );
    </cfscript>