coldfusionrailocfpdf

Using binary data as a source in Railo's cfpdf tag


So I am saving PDF blob in a database and trying to retrieve it and display it on a page. When i run the code on Coldfusion 10 it runs as expected. However, when i move the same exact code over to Railo 4.2.1.0 I get an error.

I'm curious if it is possible to pass binary data into CFPDF Source tag in Railo. If not does anyone know of a good workaround?

When i run a dump the pdfBinary data does have the correct binary information inside of it.

Thanks

Code:

<cfset tcpInformation = dataPopulatorController.getTCPInformation(session.requestID, session.personID) />

<cfset pdfBinary = tcpInformation.file_content[1]>

<cfpdf action="read" source="pdfBinary" name="TCPDocument">

<cfheader name="Content-Disposition" value="filename=TCP.pdf" />
<cfcontent type="application/pdf" variable="#toBinary(TCPDocument)#" />

Error I get on Railo:

The Error Occurred in /****/tcpviewer.cfm: line 7 5: 6: 7: 8: 9:

Java Stacktrace file or directory pdfBinary not exist at railo.commons.io.res.util.ResourceUtil.toResourceExisting(ResourceUtil.java:199):199 at railo.commons.io.res.util.ResourceUtil.toResourceExisting(ResourceUtil.java:164):164 at railo.runtime.tag.PDF.toPDFDocument(PDF.java:1207):1207 at railo.runtime.tag.PDF.doActionRead(PDF.java:1033):1033 at railo.runtime.tag.PDF.doEndTag(PDF.java:568):568 at onboarding.views.tcpviewer_cfm$cf.call(/onboarding/views/tcpviewer.cfm:7):7 at railo.runtime.PageContextImpl.doInclude(PageContextImpl.java:913):913 at railo.runtime.PageContextImpl.doInclude(PageContextImpl.java:865):865 at railo.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:206):206 at railo.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:18):18 at railo.runtime.PageContextImpl.execute(PageContextImpl.java:2218):2218 at railo.runtime.PageContextImpl.execute(PageContextImpl.java:2185):2185 at railo.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:332):332 at railo.loader.servlet.CFMLServlet.service(CFMLServlet.java:29):29 at javax.servlet.http.HttpServlet.service(HttpServlet.java:728):728 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305):305 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210):210 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222):222 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123):123 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472):472 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171):171 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99):99 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947):947 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118):118 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408):408 at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200):200 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589):589 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310):310 at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source):-1 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source):-1 at java.lang.Thread.run(Unknown Source):-1


Solution

  • When reading from a binary variable source in Railo it seems you need to wrap it with #s:

    <cfpdf action="read" source="#pdfBinary#" name="TCPDocument">
    

    But as Leigh says, there's no need to re-read the variable using CFPDF to output the content to the browser:

    <cfset tcpInformation = dataPopulatorController.getTCPInformation(session.requestID, session.personID) />
    <cfset pdfBinary = tcpInformation.file_content[1]>
    <cfheader name="Content-Disposition" value="filename=TCP.pdf" />
    <cfcontent type="application/pdf" variable="#pdfBinary#" />