Skip to main content
Inspiring
July 8, 2006
Question

pdfs, cfcs and webservices

  • July 8, 2006
  • 18 replies
  • 1763 views
Hopefully someone can help me with this so I figure out what I'm doing
wrong.

I have a cfc that is using cffile to grab pdfs, avis, mpegs, etc. and
returning it to the user. For some reason can't get it through to the user.
On the "invoking page" I'm using cfheader and cfcontent to try and send the
file as an attachment to the user, but it won't work. If I cfdump the
variable I get data, but I'm never prompted to open/save the file. Using
regular cfm pages I have no problems. I have tried read, readbinary,
toBinary with no luck.

Also I need this function to accessible as a webservice and trying that
keeps returning an error about an invalid wsdl file and couldn't create
stubs, but calling it from the same site results in the issue above but no
wsdl error.

CFC Code
-----------
<cffunction name="getFile" access="remote" displayname="Get File" hint="I
get a file based on the passed id.">
<cfargument name="docID" type="string" required="yes">
<cfset var doc = '' />
<cfset var filePath = expandPath('../Web_Support_Doc/') & arguments.docID
/>
<cffile action="readbinary" file="#filePath#" variable="doc" />
<cfreturn doc>
</cffunction>

Invocation Code
------------------
<cfsilent>
<cfset docFile =
createObject('component','_cfcs.file').getFile('1255KITG.pdf') />
</cfsilent>

<cfheader name="Content-Disposition" value="attachment;
filename=1255KITG.pdf">
<cfcontent type="application/unknown" file="#docFile#">

Web Service invocation code
---------------------------------
<cfset docFile =
createObject('webservice',' http://innet/_cfcs/file.cfc?method=getFile&docID=#url.docID#')
/>

I'm using the same cfheader/cfcontent code from above to send to user.

Any help would be greatly appreciated.

--
Bryan Ashcraft (remove brain to reply)
Web Application Developer
Wright Medical Technologies, Inc.
------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/



This topic has been closed for replies.

18 replies

Inspiring
July 11, 2006
I have played with it some more and maybe getting closer. This gets a
file to download, but it is apparently corrupted and Adobe
Reader/Acrobat can not open it.


fileServing.cfm
---------------
<cfset myFile="test.pdf">

<cfheader name="Content-Disposition" value="attachment; filename=#Myfile#">

<cfset testObj = createObject("webservice",
" http://playground/probono/fileServing.cfc?wsdl")>

<cfcontent type="application/unknown">
<cfoutput>#binaryDecode(testObj.serveFile(myFile),"Hex")#</cfoutput>

fileServing.cfc
---------------
<cfcomponent>
<cffunction name="serveFile" access="remote" returntype="string">
<cfargument name="fileToServe" required="yes" type="string">

<cfset var fileObj = "">
<cfset var returnVar = "">

<cffile action="readbinary"
file="g:\playground\probono\#arguments.fileToServe#" variable="fileObj">
<cfset returnVar = binaryEncode(fileObj,"Hex")>

<cfreturn returnVar>
</cffunction>
</cfcomponent>
Inspiring
July 11, 2006
I have been playing with this just a bit. I can make this work.

fileServing.cfm
---------------
<cfset testObj = createObject("component", "fileServing")>

<cfset testObj.serveFile("test.pdf")>

fileServing.cfc
---------------
<cfcomponent>
<cffunction name="serveFile" access="remote" returntype="void">
<cfargument name="fileToServe" required="yes" type="string">

<cfheader name="Content-Disposition" value="attachment;
filename=#arguments.fileToServe#">
<cfcontent file="G:\Playground\ProBono\#arguments.fileToServe#"
reset="no" type="application/unknown">

</cffunction>
</cfcomponent>

But when I try to use it as a web service, I get errors. I suspect that
a web service works differently and may not be easily usable in this
manner.

A clearer idea of what you goal is could be useful.
Inspiring
July 11, 2006
If I use this code:

<!--- Send HTTP request for file from intranet and serve file to user--->
<cfhttp method="get" url=" http://domain/load_doc.cfm?doc=#url.doc#"
timeout="60" throwonerror="yes"></cfhttp>
</cfsilent>
<!--- Set default headers for serving file and serve file up to user--->
<cfheader name="Content-Type" value="pdf">
<cfheader name="Content-Disposition" value="attachment; filename=#url.doc#">
<cfcontent type="application/pdf">

<cfoutput>#cfhttp.filecontent#</cfoutput>

To call this code:

<!--- Define the full path to the docs --->
<cfset doc_path = expandPath("../../Web_Support_Doc/") & 'ACCSLIT.pdf' />

<!--- Verify the requested file exists --->
<cfif fileExists(doc_path)>

<!--- If file exists, serve it up --->
<cfcontent type="application/pdf" file="#doc_path#" />
<cfabort />

<!--- Otherwise display error --->
<cfelse>
<cfset error = "We're sorry, the file you have requested is not available."
/>
<cfinclude template="error.cfm" />
<cfabort />
</cfif>


It works fine. But if I use this code:

<cfset docFile =
createObject('webservice',' http://innet/_cfcs/docLoader.cfc?method=read&docID=#url.docID#')
/>
<cfheader name="Content-Type" value="pdf">
<cfheader name="Content-Disposition" value="attachment;
filename=#url.docID#">
<cfcontent type="application/pdf">
<cfoutput>#docFile#</cfoutput>
<cfabort />

To call this code:

<cfcomponent>
<cffunction name="read" access="remote" displayname="Read File" hint="I
read a file based on the passed id." output="false" returntype="binary">
<cfargument name="docID" type="string" required="yes">
<cfset var doc = '' />
<cfset var filePath = expandPath('../Web_Support_Doc/') & arguments.docID
/>
<cfif fileExists(filePath)>
<cffile variable="doc" action="readbinary" file="#filePath#" />
</cfif>
<cfreturn doc />
</cffunction>
</cfcomponent>

It doesn't.

--
Bryan Ashcraft (remove brain to reply)
Web Application Developer
Wright Medical Technologies, Inc.
------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


"Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
news:e90s98$c07$1@forums.macromedia.com...
> Can you provide some working, NON-CFC code. Serving up documents like
> this is something I've only done once in the last ten years, and I do not
> remember all the details.
>
> Bash **AdobeCommunityExpert** wrote:
>> Well that didn't work either. :(
>>


Inspiring
July 11, 2006
Can you provide some working, NON-CFC code. Serving up documents like
this is something I've only done once in the last ten years, and I do
not remember all the details.

Bash **AdobeCommunityExpert** wrote:
> Well that didn't work either. :(
>
Inspiring
July 11, 2006
Well that didn't work either. :(

--
Bryan Ashcraft (remove brain to reply)
Web Application Developer
Wright Medical Technologies, Inc.
------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


"Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
news:e8uk8h$ek2$1@forums.macromedia.com...
> What about putting the code to send the documents to the client in the cfc
> function. This is the only way I can even imagine this working as a
> webservice. Because, otherwise, what is the returntype for "document?"
>
>
>
> Bash **AdobeCommunityExpert** wrote:
>> No ideas? :(
>>


Inspiring
July 11, 2006
I'm obviously brain dead due to this deadline as I didn't even think of
that. Thanks! I'll give it a shot.

--
Bryan Ashcraft (remove brain to reply)
Web Application Developer
Wright Medical Technologies, Inc.
------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


"Ian Skinner" <ian.skinner@bloodsource.org> wrote in message
news:e8uk8h$ek2$1@forums.macromedia.com...
> What about putting the code to send the documents to the client in the cfc
> function. This is the only way I can even imagine this working as a
> webservice. Because, otherwise, what is the returntype for "document?"
>
>
>
> Bash **AdobeCommunityExpert** wrote:
>> No ideas? :(
>>


Inspiring
July 10, 2006
What about putting the code to send the documents to the client in the
cfc function. This is the only way I can even imagine this working as a
webservice. Because, otherwise, what is the returntype for "document?"



Bash **AdobeCommunityExpert** wrote:
> No ideas? :(
>
Inspiring
July 10, 2006
No ideas? :(

--
Bryan Ashcraft (remove brain to reply)
Web Application Developer
Wright Medical Technologies, Inc.
------------------------------------------------------------------
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


"Bash **AdobeCommunityExpert**" <bashcraft@wmtBRAIN.com> wrote in message
news:e8n26h$fck$1@forums.macromedia.com...
> Hopefully someone can help me with this so I figure out what I'm doing
> wrong.
>
> I have a cfc that is using cffile to grab pdfs, avis, mpegs, etc. and
> returning it to the user. For some reason can't get it through to the
> user. On the "invoking page" I'm using cfheader and cfcontent to try and
> send the file as an attachment to the user, but it won't work. If I cfdump
> the variable I get data, but I'm never prompted to open/save the file.
> Using regular cfm pages I have no problems. I have tried read, readbinary,
> toBinary with no luck.
>
> Also I need this function to accessible as a webservice and trying that
> keeps returning an error about an invalid wsdl file and couldn't create
> stubs, but calling it from the same site results in the issue above but no
> wsdl error.
>
> CFC Code
> -----------
> <cffunction name="getFile" access="remote" displayname="Get File" hint="I
> get a file based on the passed id.">
> <cfargument name="docID" type="string" required="yes">
> <cfset var doc = '' />
> <cfset var filePath = expandPath('../Web_Support_Doc/') & arguments.docID
> />
> <cffile action="readbinary" file="#filePath#" variable="doc" />
> <cfreturn doc>
> </cffunction>
>
> Invocation Code
> ------------------
> <cfsilent>
> <cfset docFile =
> createObject('component','_cfcs.file').getFile('1255KITG.pdf') />
> </cfsilent>
>
> <cfheader name="Content-Disposition" value="attachment;
> filename=1255KITG.pdf">
> <cfcontent type="application/unknown" file="#docFile#">
>
> Web Service invocation code
> ---------------------------------
> <cfset docFile =
> createObject('webservice',' http://innet/_cfcs/file.cfc?method=getFile&docID=#url.docID#')
> />
>
> I'm using the same cfheader/cfcontent code from above to send to user.
>
> Any help would be greatly appreciated.
>
> --
> Bryan Ashcraft (remove brain to reply)
> Web Application Developer
> Wright Medical Technologies, Inc.
> ------------------------------------------------------------------
> Macromedia Certified Dreamweaver Developer
> Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/
>
>
>