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 12, 2006
Nevermind had a Acrobat Reader install acting up for some reason. Reinstall
seems to have fixed it.

Thanks Again for all the help Ian!

--
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:e93hh6$m1b$1@forums.macromedia.com...
> Apparently this is an IE issue as it works fine FF.
>
> --
> 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:e93fdq$jfs$1@forums.macromedia.com...
>> Apparently these servers just don't like me. I get the binary data dumped
>> on the page using your method.
>>
>> Basically I get a lot of this stuff:
>>
>> %PDF-1.2 %?? 12 0 obj << /Length 13 0 R /Filter /FlateDecode >> stream
>> H?????????%=??6$Y`'??`gl??? ???\V????
>> TF??=O??2#fS??(?X?o??1#???&k????z?@v
>> ?'?8??5`qo!.?=??7???+????????Rf??
>> ????h?????�f?w??L!????????2{WwU?? \??fkB???]???!????? iw??]???Cg?
>> ?? sf???;?P???0????~Ig3h??
>>
>> --
>> 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:e9196n$rj2$1@forums.macromedia.com...
>>> Well if one tries hard enough one can do most anything. The following
>>> code is serving up PDF files from a web service! For some reason, I
>>> could not get this to work by sending the data directly to the client
>>> with the cfcontent tag, but by writing the data to a temp file and then
>>> sending that file to the client with cfcontent worked.
>>>
>>> Hopefully you can build on this to solve your problem.
>>>
>>> fileServing.cfm
>>> ---------------
>>> <cfset myFile="test.pdf">
>>>
>>> <cfheader name="Content-Type" value="pdf">
>>> <cfheader name="Content-Disposition" value="attachment;
>>> filename=#Myfile#">
>>>
>>> <cfset testObj = createObject("webservice",
>>> " http://playground/probono/fileServing.cfc?wsdl")>
>>>
>>> <cffile action="write" file="g:\playground\probono\tempServe.pdf"
>>> output="#BinaryDecode(testObj.serveFile(myFile),'Base64')#"
>>> addnewline="No" >
>>>
>>> <cfcontent type="application/pdf"
>>> file="g:\playground\probono\tempServe.pdf" reset="no">
>>>
>>>
>>> fileServing.cfc
>>> ---------------
>>> <cfcomponent>
>>> <cffunction name="serveFile" access="remote" returntype="string">
>>> <cfargument name="fileToServe" required="yes" type="string">
>>>
>>> <cfset var fileObj = "">
>>> <cfset var returnVar = "">
>>> <cfset var file = "">
>>>
>>> <cffile action="readBinary"
>>> file="g:\playground\probono\#arguments.fileToServe#" variable="fileObj">
>>> <cfset returnVar = binaryEncode(fileObj,"Base64")>
>>>
>>> <cfreturn returnVar>
>>> </cffunction>
>>> </cfcomponent>
>>
>>
>
>


Inspiring
July 12, 2006
Apparently this is an IE issue as it works fine FF.

--
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:e93fdq$jfs$1@forums.macromedia.com...
> Apparently these servers just don't like me. I get the binary data dumped
> on the page using your method.
>
> Basically I get a lot of this stuff:
>
> %PDF-1.2 %?? 12 0 obj << /Length 13 0 R /Filter /FlateDecode >> stream
> H?????????%=??6$Y`'??`gl??? ???\V????
> TF??=O??2#fS??(?X?o??1#???&k????z?@v
> ?'?8??5`qo!.?=??7???+????????Rf??
> ????h?????�f?w??L!????????2{WwU?? \??fkB???]???!????? iw??]???Cg?
> ?? sf???;?P???0????~Ig3h??
>
> --
> 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:e9196n$rj2$1@forums.macromedia.com...
>> Well if one tries hard enough one can do most anything. The following
>> code is serving up PDF files from a web service! For some reason, I
>> could not get this to work by sending the data directly to the client
>> with the cfcontent tag, but by writing the data to a temp file and then
>> sending that file to the client with cfcontent worked.
>>
>> Hopefully you can build on this to solve your problem.
>>
>> fileServing.cfm
>> ---------------
>> <cfset myFile="test.pdf">
>>
>> <cfheader name="Content-Type" value="pdf">
>> <cfheader name="Content-Disposition" value="attachment;
>> filename=#Myfile#">
>>
>> <cfset testObj = createObject("webservice",
>> " http://playground/probono/fileServing.cfc?wsdl")>
>>
>> <cffile action="write" file="g:\playground\probono\tempServe.pdf"
>> output="#BinaryDecode(testObj.serveFile(myFile),'Base64')#"
>> addnewline="No" >
>>
>> <cfcontent type="application/pdf"
>> file="g:\playground\probono\tempServe.pdf" reset="no">
>>
>>
>> fileServing.cfc
>> ---------------
>> <cfcomponent>
>> <cffunction name="serveFile" access="remote" returntype="string">
>> <cfargument name="fileToServe" required="yes" type="string">
>>
>> <cfset var fileObj = "">
>> <cfset var returnVar = "">
>> <cfset var file = "">
>>
>> <cffile action="readBinary"
>> file="g:\playground\probono\#arguments.fileToServe#" variable="fileObj">
>> <cfset returnVar = binaryEncode(fileObj,"Base64")>
>>
>> <cfreturn returnVar>
>> </cffunction>
>> </cfcomponent>
>
>


Inspiring
July 12, 2006
Apparently these servers just don't like me. I get the binary data dumped on
the page using your method.

Basically I get a lot of this stuff:

%PDF-1.2 %?? 12 0 obj << /Length 13 0 R /Filter /FlateDecode >> stream
H?????????%=??6$Y`'??`gl??? ???\V????
TF??=O??2#fS??(?X?o??1#???&k????z?@v
?'?8??5`qo!.?=??7???+????????Rf??
????h?????�f?w??L!????????2{WwU?? \??fkB???]???!????? iw??]???Cg? ??
sf???;?P???0????~Ig3h??

--
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:e9196n$rj2$1@forums.macromedia.com...
> Well if one tries hard enough one can do most anything. The following
> code is serving up PDF files from a web service! For some reason, I could
> not get this to work by sending the data directly to the client with the
> cfcontent tag, but by writing the data to a temp file and then sending
> that file to the client with cfcontent worked.
>
> Hopefully you can build on this to solve your problem.
>
> fileServing.cfm
> ---------------
> <cfset myFile="test.pdf">
>
> <cfheader name="Content-Type" value="pdf">
> <cfheader name="Content-Disposition" value="attachment;
> filename=#Myfile#">
>
> <cfset testObj = createObject("webservice",
> " http://playground/probono/fileServing.cfc?wsdl")>
>
> <cffile action="write" file="g:\playground\probono\tempServe.pdf"
> output="#BinaryDecode(testObj.serveFile(myFile),'Base64')#"
> addnewline="No" >
>
> <cfcontent type="application/pdf"
> file="g:\playground\probono\tempServe.pdf" reset="no">
>
>
> fileServing.cfc
> ---------------
> <cfcomponent>
> <cffunction name="serveFile" access="remote" returntype="string">
> <cfargument name="fileToServe" required="yes" type="string">
>
> <cfset var fileObj = "">
> <cfset var returnVar = "">
> <cfset var file = "">
>
> <cffile action="readBinary"
> file="g:\playground\probono\#arguments.fileToServe#" variable="fileObj">
> <cfset returnVar = binaryEncode(fileObj,"Base64")>
>
> <cfreturn returnVar>
> </cffunction>
> </cfcomponent>


Inspiring
July 12, 2006
Very good point. I was planning using the makeunique option of cffile to
help with that. Adding a lock could further enhance this. Thanks!

--
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:e91a6t$soo$1@forums.macromedia.com...
>I just thought of something of which you should be aware. I believe there
>is a potential for a race condition during your save it, serve it, delete
>it cycle.
>
> I suspect you will want to lock or otherwise control the access to this
> logic so that a second user is not saving a new file just before an
> earlier user is to be served and thus they both get the second user's
> file.
>
> Bash **AdobeCommunityExpert** wrote:
>> You rock!!!!
>>
>> Thank you so much. I'll just have to save it, serve it, delete it!
>>


Inspiring
July 11, 2006
I just thought of something of which you should be aware. I believe
there is a potential for a race condition during your save it, serve it,
delete it cycle.

I suspect you will want to lock or otherwise control the access to this
logic so that a second user is not saving a new file just before an
earlier user is to be served and thus they both get the second user's file.

Bash **AdobeCommunityExpert** wrote:
> You rock!!!!
>
> Thank you so much. I'll just have to save it, serve it, delete it!
>
Inspiring
July 11, 2006
You rock!!!!

Thank you so much. I'll just have to save it, serve it, delete it!

--
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:e9196n$rj2$1@forums.macromedia.com...
> Well if one tries hard enough one can do most anything. The following
> code is serving up PDF files from a web service! For some reason, I could
> not get this to work by sending the data directly to the client with the
> cfcontent tag, but by writing the data to a temp file and then sending
> that file to the client with cfcontent worked.
>
> Hopefully you can build on this to solve your problem.
>
> fileServing.cfm
> ---------------
> <cfset myFile="test.pdf">
>
> <cfheader name="Content-Type" value="pdf">
> <cfheader name="Content-Disposition" value="attachment;
> filename=#Myfile#">
>
> <cfset testObj = createObject("webservice",
> " http://playground/probono/fileServing.cfc?wsdl")>
>
> <cffile action="write" file="g:\playground\probono\tempServe.pdf"
> output="#BinaryDecode(testObj.serveFile(myFile),'Base64')#"
> addnewline="No" >
>
> <cfcontent type="application/pdf"
> file="g:\playground\probono\tempServe.pdf" reset="no">
>
>
> fileServing.cfc
> ---------------
> <cfcomponent>
> <cffunction name="serveFile" access="remote" returntype="string">
> <cfargument name="fileToServe" required="yes" type="string">
>
> <cfset var fileObj = "">
> <cfset var returnVar = "">
> <cfset var file = "">
>
> <cffile action="readBinary"
> file="g:\playground\probono\#arguments.fileToServe#" variable="fileObj">
> <cfset returnVar = binaryEncode(fileObj,"Base64")>
>
> <cfreturn returnVar>
> </cffunction>
> </cfcomponent>


Inspiring
July 11, 2006
Well if one tries hard enough one can do most anything. The following
code is serving up PDF files from a web service! For some reason, I
could not get this to work by sending the data directly to the client
with the cfcontent tag, but by writing the data to a temp file and then
sending that file to the client with cfcontent worked.

Hopefully you can build on this to solve your problem.

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

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

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

<cffile action="write" file="g:\playground\probono\tempServe.pdf"
output="#BinaryDecode(testObj.serveFile(myFile),'Base64')#"
addnewline="No" >

<cfcontent type="application/pdf"
file="g:\playground\probono\tempServe.pdf" reset="no">


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

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

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

<cfreturn returnVar>
</cffunction>
</cfcomponent>
Inspiring
July 11, 2006
A small sample of the data dump would be fine, I was just curious if it
was an obvious encoding?

I am making a bit of progress, there is an error in the code, and the
error display is what is being downloaded to the reader.

Bash **AdobeCommunityExpert** wrote:
> cfhttp.filecontent is simply the data returned from the cfhttp call. I can
> post the big binary data dump if you want, but that is what the variable
> contains.
>
> The reason I'm doing this is because we have the files stored one server but
> need them to be accessible from two separate servers. I wanted to use a web
> service as it reduces the amount of code involved.
>
> Thanks so much for all the effort you have put into this, I know I have been
> banging my head against it for a while now.
>
Inspiring
July 11, 2006
cfhttp.filecontent is simply the data returned from the cfhttp call. I can
post the big binary data dump if you want, but that is what the variable
contains.

The reason I'm doing this is because we have the files stored one server but
need them to be accessible from two separate servers. I wanted to use a web
service as it reduces the amount of code involved.

Thanks so much for all the effort you have put into this, I know I have been
banging my head against it for a while now.

--
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:e9164l$o5d$1@forums.macromedia.com...
> Can you provide a sample of what #cfhttp.filecontent# is in this sample?
>
>
> <!--- 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>


Inspiring
July 11, 2006
Can you provide a sample of what #cfhttp.filecontent# is in this sample?


<!--- 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>