Quantcast
Channel: Adobe Community : Popular Discussions - ColdFusion
Viewing all articles
Browse latest Browse all 14291

How can I return a PDF file from server using restful api

$
0
0

Wondering how to return a PDF file from the server using the restful api.

 

A document id is provided, which retrieves a record that has the file path and file name information.

From there the file is retrieved into a variable.

 

I have tried returning as Binary Base64 with a returntype = binary in the api

 

<cfcomponent restpath="document" rest="true" output="false" extends="cfc.document">

     <cffunction name="getDocument" access="remote" output="false" httpmethod="get" returntype="binary" restpath="view/{documentId: \d+}" >

          <cfargument name="documentId" required="true" type="numeric" restargsource="path">

 

          <cfset REQUEST.sessionObj = REQUEST.securityObj.checkSession(REQUEST.sessionKey)>

          <cfset LOCAL.documentData = getDocumentData(REQUEST.sessionObj.userId, arguments.documentId, REQUEST.sessionObj.locale, REQUEST.sessionObj.languageId)>

 

          <cfreturn documentData>

     </cffunction>

</cfcomponent>

 

Next file cfc.document

<cfcomponent name="document" output="false" extends="cfc.metadata.document">

     <cffunction name="getDocumentData" output="no" returntype="any">

          <cfargument name="userId" type="numeric" required="yes">

          <cfargument name="documentId" type="numeric" required="yes">

          <cfargument name="locale" type="string" required="yes">

          <cfargument name="languageId" type="numeric" required="yes">

 

          <cfset pdfFileContent = fileRead("C:\PDFFiles\PDFSample.pdf")>

          <cfset documentData = ToBinary(ToBase64(pdfFileContent))>

 

          <cfreturn documentData>

     </cffunction>

 

</cfcomponent>


Viewing all articles
Browse latest Browse all 14291

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>