Copy link to clipboard
Copied
Hello,
I have searched the forums extensively and still have not found a solution. What I am trying to achieve is simple, but am having problems getting it to work.
I want to pass a dynamic url string from a web mapping application to a cold fusion page that then opens the pdf file on the users browser. This is an example of the url that will be passed to this page, and based on what feature the user selects, subdir and page_id will be dynamic:
http://localhost/displayImage.cfm?subdir=60&page_id=3807444
Here is what I have so far for displayImage.cfm,it is just a start, I know I need more, possibly cfheader content? When I run this code I get an error saying the file cannot be found.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<cfquery name="Surveys" datasource="sire" dbtype="odbc">
select *
from slco_sire.dbo.surveys_doc INNER JOIN slco_sire.dbo.surveys_page
ON slco_sire.dbo.surveys_doc.doc_id = slco_sire.dbo.surveys_page.doc_id
</cfquery>
<cfset picture="#url.page_id#">
<cfset sub="#url.subdir#">
<cfcontent file="\\path\to\file\#sub#\#picture#" type="application/pdf" reset="yes">
</body>
</html>
Any help would be greatly appreciate, I am stuck.
No, the variables are not the problem.
The ColdFusion service runs under a specific user account and it is that account that must have security privileges to access the folder on the network where the PDF files reside.
You will need to have your network administrator check that for you.
Cheers
Eddie
Copy link to clipboard
Copied
Use the following to display useful debugging information so you can see what is happening:
<!--- <cfcontent file="\\path\to\file\#sub#\#picture#" type="application/pdf" reset="yes"> --->
<cfif fileExists("\\path\to\file\" & sub & "\" & picture)>
The file exists.
<cfelse>
File not found: <cfoutput>\\path\to\file\#sub#\#picture#</cfoutput>
</cfif>
Notice that I commented out the cfcontent tag, otherwise you won't see the result of this change. Also, the reset parameter is ignored when serving a file.
Cheers
Eddie
Copy link to clipboard
Copied
Hi Eddie,
Thank you so much for your help!
When I add that code, the "File not found" error appears in the browser. If I hard code the path to the pdf in the browser it finds it, but I have to add the .pdf for this to work.
This works:
file://path/to/file/60/3831529.pdf
This does not
file://path/to/file/60/3831529
Do I need to do that in the code? I thought the browser would know what to do with the application/pdf info in the cfcontent tag.
Copy link to clipboard
Copied
Yes, you need to add the extension. The cfcontent tag makes no assumptions about the file name that you pass to it. It must be a fully qualified path and file name of an existing file, otherwise it will fail.
Cheers
Eddie
Copy link to clipboard
Copied
I tried adding pdf in the string that is being passed to the cfm page:
http://localhost/displayImage.cfm?subdir={subdir}&page_id={page_id}.pdf
and I am still getting this error.
File not found: \\path\to\server\54\3492904.pdf
but if I type
\\path\to\server\54\3492904.pdf in the browser, it finds it.
Thanks.
Copy link to clipboard
Copied
Please post your test code. It sounds like it might be something as simple as a typographic error.
Cheers
Eddie
Copy link to clipboard
Copied
Here is the string I am passing from my web map:
http://localhost/displayImage.cfm?subdir={subdir}&page_id={page_id}.pdf
Here is the displayImage.cfm code, comments and all. Thanks again!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<cfquery name="Surveys" datasource="sire" dbtype="odbc">
select *
from slco_sire.dbo.surveys_doc INNER JOIN slco_sire.dbo.surveys_page
ON slco_sire.dbo.surveys_doc.doc_id = slco_sire.dbo.surveys_page.doc_id
</cfquery>
<cfset picture="#url.page_id#">
<cfset sub="#url.subdir#">
<!---<cfcontent file="\\path\to\file\#sub#\#picture#" type="application/pdf"> --->
<cfif fileExists("\\path\to\file\" & sub & "\" & picture)>
The file exists.
<cfelse>
File not found: <cfoutput>\\path\to\file\#sub#\#picture#</cfoutput>
</cfif>
</body>
</html>
Copy link to clipboard
Copied
The code looks okay.
Emily LaMunyon wrote:
but if I type
\\path\to\server\54\3492904.pdf in the browser, it finds it.
Please note that typing a UNC path and filename into the browser will tell the browser to get the file, it does not make a request to the ColdFusion service, which requires that the URL start with the "HTTP://" syntax.
Let's establish that things are working the way they should by using the simplest environment.
Put a PDF file, called example.pdf, in the root of your Web server's documents folder. For IIS it is usually "c:\inetpub\wwwroot" but substitute whatever is your correct path.
Put the following code into a script called test.cfm in the same folder:
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
</head>
<body><cfset FullName = 'c:\inetpub\wwwroot\example.pdf'>
<cfif fileExists(FullName)>
The file exists.
<cfelse>
File not found: <cfoutput>#FullName#</cfoutput>
</cfif></body>
</html>
Now, navigate to the page using the URL HTTP://localhost/test.cfm and tell us what you see.
Cheers
Eddie
Copy link to clipboard
Copied
Good morning,
When I run that code I see a page that says the file exists.
Copy link to clipboard
Copied
Okay, now replace the HTML in the body of the page with:
<cfcontent file="c:\inetpub\wwwroot\example.pdf">
Now, navigate to the page using the URL HTTP://localhost/test.cfm and tell us what you see.
Cheers
Eddie
Copy link to clipboard
Copied
The example pdf shows up! Maybe adding the variables of the page_id and subdir and what is causing problems with the original code?
Copy link to clipboard
Copied
No, the variables are not the problem.
The ColdFusion service runs under a specific user account and it is that account that must have security privileges to access the folder on the network where the PDF files reside.
You will need to have your network administrator check that for you.
Cheers
Eddie
Copy link to clipboard
Copied
Okay, I will do that. Thank you so much for your help, it is very appreciated!