Copy link to clipboard
Copied
I inherited an application a few years ago and up until today, a particular part of the code has worked flawlessly. It was supposed to upload a pdf file and attach it to a record in the database. Now, I receive a generic message and I have no clue what is wrong. I mostly am an Oracle DBA and can do enough CF to get by, until now. What can I add to this to help give me an idea of what is wrong? Thanx. In the below code piece, the cflocation line just goes on, but I can't do that here.
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to upload your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
</cfcatch>
</cftry>
I have reviewed this thread. It is now clear to me why Coldfusion is unable to find the destination directory.
When you began the thread, the value of the destination directory (newDest) was
\\TestServer\secure\Authorization\378Docs\
and the action page for the upload form was
\\TestServer\secure\Authorization\upload378Act.cfm
Destination directory and upload form appeared to have the same root directory, namely, \\TestServer\secure\Authorization\. However, in the most recent error-message, the value
...Copy link to clipboard
Copied
To get more details, temporarily try the following:
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<!--- <CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to upload your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#"> --->
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry>
I suspect you are getting a file collision.
Cheers
Eddie
Copy link to clipboard
Copied
Just
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = "#newDest#"
accept = "application/pdf">
and Coldfusion will tell you what the matter is.
Copy link to clipboard
Copied
Is the file being inserted into the database? Or does it reside on the web server and is somehow associated with a database record?
If the former, check the database table for unique constraints. If the file (or even the file name) already exists in the database and the constraint for unique binary value or unique filename is set, that could cause an issue.
Also, in your CFTRY/CFCATCH, set it to either email you a CFDUMP of cfcatch, or display it right on the page as EddieLotter suggested (remembering, of course, to remove that part before going to production.)
HTH,
^_^
Copy link to clipboard
Copied
The file is stored in a directory elsewhere on the server and a pointer to that file is stored in the database.
I put in the debugging statements and tried again. I immediately got a 500 - Internal server error. I commented out the debug statement and tried again... yet another 500. Not sure what I have done. Here is the code fragment after I commented out the debug statement.
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to upload your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
<!--- <cfdump var="#cfcatch#">
<cfabort showError="debugging"> --->
</cfcatch>
</cftry>
Copy link to clipboard
Copied
LouieWarren wrote:
The file is stored in a directory elsewhere on the server and a pointer to that file is stored in the database.
If this is the process of uploading a file then surely there won't yet be a record in the database. Right?
Cheers
Eddie
Copy link to clipboard
Copied
I am assuming. The error is on the Production machine and it is in control of the government DBAs... I have a bunch of hoops to jump through to get a query run. Sucks to be me, huh? I'll have to submit the request. Thank you.
Copy link to clipboard
Copied
LouieWarren wrote:
The file is stored in a directory elsewhere on the server and a pointer to that file is stored in the database.
I put in the debugging statements and tried again. I immediately got a 500 - Internal server error. I commented out the debug statement and tried again... yet another 500. Not sure what I have done. Here is the code fragment after I commented out the debug statement.
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to upload your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
<!--- <cfdump var="#cfcatch#">
<cfabort showError="debugging"> --->
</cfcatch>
</cftry>
What happens when you comment out the entire code, like this?
<!---
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We
were unable to upload your file. Please try
again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry>
--->
<cfdump var="#form#">
Do you get the form fields? If so, which?
Copy link to clipboard
Copied
500 Internal server error
Copy link to clipboard
Copied
Then something went wrong with the form submission. Could you share the form page with the forum?
Copy link to clipboard
Copied
I am a CF novice. I hope I've included the right part of the code. Here's the entire calling .cfm file:
<HTML>
<HEAD>
<TITLE>Upload 378</TITLE>
<link rel=stylesheet href="REDProj.css">
</HEAD>
<BODY>
<!--- <CFOUTPUT>#CGI.QUERY_STRING#</CFOUTPUT> --->
<CFOUTPUT>
<CFSET newDest = #authfileroot#&"378Docs\">
</CFOUTPUT>
<CFQUERY datasource="#datasource#" name="Getdata">
select FileLink from FM_FORM378_TRAN
where F378_ID=#FORM.F378_ID#
</CFQUERY>
<cfoutput>
<cfset oldfile=#newDest#&#Getdata.FileLink#>
</cfoutput>
<cfif #Getdata.FileLink# neq ''>
<cfif fileexists("#oldfile#")>
<cftry>
<cffile action = "delete" file=#oldfile#>
<cfcatch>
<!--- <CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to delete your old file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#"> -->
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry>
</cfif>
</cfif>
<CFIF IsDefined("URL.Action") AND URL.Action is "Upload">
<CFSET F378_ID = #FORM.F378_ID#>
<CFSET IE_PMO_DT = #FORM.IE_PMO_DT#>
<CFSET FMBIC_DT = #FORM.FMBIC_DT#>
<CFSET FILENAME = #FORM.requiredFILENAME#>
<CFSET IE_PMOMILCON_DT = #FORM.IE_PMOMILCON_DT#>
<CFIF variables.FILENAME is "">
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=You must select a file.&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
</CFIF>
<!--- <cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to upload your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry> --->
<cfdump var="#form#">
<CFOUTPUT><CFSET oldName = #newDest# & #CFFILE.ServerFile#></CFOUTPUT>
<CFOUTPUT><CFSET newName = #newDest# & #variables.F378_ID# &"_"& #CFFILE.ServerFile#></CFOUTPUT>
<cftry>
<CFFILE ACTION="Rename"
SOURCE=#oldName#
DESTINATION=#newName#>
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to rename your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
</cfcatch>
</cftry>
<CFQUERY datasource="#datasource#" name="add378">
update FM_FORM378_TRAN
set IE_PMO_DT=to_date('#FORM.IE_PMO_DT#','mm/dd/yyyy') ,
FMBIC_DT=to_date('#FORM.FMBIC_DT#','mm/dd/yyyy'),
IE_PMOMILCON_DT=to_date('#FORM.IE_PMOMILCON_DT#','mm/dd/yyyy'),
FileLink=#FORM.F378_ID# ||'_'|| '#CFFILE.ServerFile#'
where F378_ID=#FORM.F378_ID#
</CFQUERY>
<script language=javascript type='text/javascript'>
//opener.window.location=opener.window.location;
opener.window.location.reload();
self.close();
//return false;
</SCRIPT>
<CFELSE>
How did you get here!!!
<script language=javascript type='text/javascript'>
self.close();
</SCRIPT>
</CFIF>
</BODY>
</HTML>
Hopefully that shows what you need. Sorry to be dense.
Copy link to clipboard
Copied
That was the action page. I requested the form page.
In any case, you could do with fewer <cfoutput> tags and fewer # symbols:
<HTML>
<HEAD>
<TITLE>Upload 378</TITLE>
<link rel=stylesheet href="REDProj.css">
</HEAD>
<BODY>
<!--- <CFOUTPUT>#CGI.QUERY_STRING#</CFOUTPUT> --->
<CFSET newDest = authfileroot & "378Docs\">
<CFQUERY datasource="#datasource#" name="Getdata">
select FileLink from FM_FORM378_TRAN
where F378_ID=#FORM.F378_ID#
</CFQUERY>
<cfset oldfile=newDest & Getdata.FileLink>
<cfif Getdata.FileLink neq ''>
<cfif fileexists("#oldfile#")>
<cftry>
<cffile action = "delete" file="#oldfile#">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to delete your old file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOM ILCON_DT#"> -->
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry>
</cfif>
</cfif>
<CFIF IsDefined("URL.Action") AND URL.Action is "Upload">
<CFSET F378_ID = FORM.F378_ID>
<CFSET IE_PMO_DT = FORM.IE_PMO_DT>
<CFSET FMBIC_DT = FORM.FMBIC_DT>
<CFSET FILENAME = FORM.requiredFILENAME>
<CFSET IE_PMOMILCON_DT = FORM.IE_PMOMILCON_DT>
<CFIF variables.FILENAME is "">
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=You must select a file.&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOMIL CON_DT#">
</CFIF>
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = "#newDest#"
accept = "application/pdf">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to upload your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#
&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry>
<cfdump var="#form#">
<CFSET oldName = newDest & CFFILE.ServerFile>
<CFSET newName = newDest & variables.F378_ID & "_" & CFFILE.ServerFile>
<cftry>
<CFFILE ACTION="Rename"
SOURCE="#oldName#"
DESTINATION="#newName#">
<cfcatch>
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=We were unable to rename your file. Please try again..&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOM ILCON_DT#">
</cfcatch>
</cftry>
<CFQUERY datasource="#datasource#" name="add378">
update FM_FORM378_TRAN
set IE_PMO_DT=to_date('#FORM.IE_PMO_DT#','mm/dd/yyyy') ,
FMBIC_DT=to_date('#FORM.FMBIC_DT#','mm/dd/yyyy'),
IE_PMOMILCON_DT=to_date('#FORM.IE_PMOMILCON_DT#','mm/dd/yyyy'),
FileLink=#FORM.F378_ID# ||'_'|| '#CFFILE.ServerFile#'
where F378_ID=#FORM.F378_ID#
</CFQUERY>
<script language=javascript type='text/javascript'>
//opener.window.location=opener.window.location;
opener.window.location.reload();
self.close();
//return false;
</SCRIPT>
<CFELSE>
How did you get here!!!
<script language=javascript type='text/javascript'>
self.close();
</SCRIPT>
</CFIF>
</BODY>
</HTML>
Copy link to clipboard
Copied
As I said earlier, I'm a novice with very little CF experience. I'm normally an Oracle DBA and was thrown into this because the customer thought that is what they needed. In actuality, they needed a CF developer with a little Oracle experience as opposed to the opposite. That said, you are talking about the pop-up form to select the file to upload? What tag would that have? Once again, sorry to be dense.
Copy link to clipboard
Copied
This?
<FORM method="post" action="upload378Act.cfm?Action=Upload" onSubmit="return checkform(this)" enctype="multipart/form-data">
<TABLE width="100%">
<tr>
<td align=center valign="top" colspan="3">
<FONT style="FONT: bold 12pt Arial; color: darkblue;">
Upload 378
</FONT>
<BR>
<CFIF IsDefined("URL.ERROR")>
<FONT style="FONT: bold 8pt Arial; color: red;">
<CFOUTPUT>#URL.ERROR#</CFOUTPUT>
</FONT>
</CFIF>
<INPUT type="hidden" name="F378_ID" value="<CFOUTPUT>#URL.F378_ID#</CFOUTPUT>">
</td>
</tr>
<tr>
<td>
<cfif #getdata.budgetprogramID# is 120 or #getdata.budgetprogramID# is 110>
<b>SAF/IEI PMO MILCON Date</b>
</cfif>
</td>
<td><b>SAF/IEI PMO Appr Date</b></td>
<td><b>SAF/FM Coord Date</b></td>
</tr>
<tr>
<CFOUTPUT>
<td>
<cfif #getdata.budgetprogramID# is 120 or #getdata.budgetprogramID# is 110>
<INPUT type="text" name="IE_PMOMILCON_DT" size="15" <CFIF IsDefined("URL.IE_PMOMILCON_DT")> value="#URL.IE_PMOMILCON_DT#"</CFIF> readonly>
<A HREF="2"
onClick="cal.select(document.forms[0].IE_PMOMILCON_DT,'anchor2','MM/dd/yyyy'); return false;"
NAME="anchor2" ID="anchor2">
<img alt="Select a date" height=16 width=21 src="../../Images/pdate.gif" border=0>
</A>
<cfelse>
<INPUT name="IE_PMOMILCON_DT" type="hidden" <CFIF IsDefined("URL.IE_PMOMILCON_DT")> value="#URL.IE_PMOMILCON_DT#"</CFIF>>
</cfif>
</td>
<td><INPUT type="text" name="IE_PMO_DT" size="15" <CFIF IsDefined("URL.IE_PMO_DT")> value="#URL.IE_PMO_DT#"</CFIF> readonly>
<A HREF="1"
onClick="cal.select(document.forms[0].IE_PMO_DT,'anchor1','MM/dd/yyyy'); return false;"
NAME="anchor1" ID="anchor1">
<img alt="Select a date" height=16 width=21 src="../../Images/pdate.gif" border=0>
</A>
</td>
<td><INPUT type="text" name="FMBIC_DT" size="15" <CFIF IsDefined("URL.FMBIC_DT")> value="#URL.FMBIC_DT#"</CFIF> readonly>
<A HREF="3"
onClick="cal.select(document.forms[0].FMBIC_DT,'anchor3','MM/dd/yyyy'); return false;"
NAME="anchor3" ID="anchor3">
<img alt="Select a date" height=16 width=21 src="../../Images/pdate.gif" border=0>
</A>
</td>
</CFOUTPUT>
</tr>
<tr>
<td colspan="3">
<b>Select File and Upload</b><BR>
<input type="file" name="requiredFILENAME" size="50"><BR>
*Only file type accepted: *.pdf
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="submit" value="Save" style="BACKGROUND-COLOR:#ffffcc;FONT: bold 8pt Arial;COLOR: #000080;BORDER-LEFT: 0px; BORDER-TOP:0px; width:100px; height:18px">
</td>
</tr>
</TABLE>
</FORM>
Copy link to clipboard
Copied
I've been sidetracked with that other issue we worked through. Did I give the code snippet you needed?
The customer sent an e-mail this morning stating that she remembered this issue happening before and that the solution or workaround was the filename could not contain special characters. I don't think that is it, but at this point, since I don't really know what I'm doing, I'm willing to try anything.
Copy link to clipboard
Copied
Yes, you provided the relevant snippets.
Can you reproduce the problem yourself or are you relying on the customer to do the testing?
Cheers
Eddie
Copy link to clipboard
Copied
I do all the testing. The customer, being impatient, constantly tries to upload, I am assuming, thinking that time will solve the issue, or that I fixed it and didn't tell her. She just recently sent the e-mail that said, previously, the filename was including the entire path of where the file resided, which caused problems. That was in 2012, and the programmer at the time, fixed it. The customer has no clue. I liken their knowledge of the app and how it works to the old custom of bleeding the patient to get out the bad blood.
All that aside, in my testing, it still fails to upload.
Copy link to clipboard
Copied
Okay, since you can reproduce the problem we may have something to work with.
Look at my first response to your original post. I removed the redirect you are using to handle errors and added code to display the exception details. Please use that code and post the text of the exception for us to have a look at.
Cheers
Eddie
Copy link to clipboard
Copied
I think I put it in the right place:
<CFIF IsDefined("URL.Action") AND URL.Action is "Upload">
<CFSET F378_ID = #FORM.F378_ID#/>
<CFSET IE_PMO_DT = #FORM.IE_PMO_DT#/>
<CFSET FMBIC_DT = #FORM.FMBIC_DT#/>
<CFSET FILENAME = #FORM.requiredFILENAME#/>
<CFSET IE_PMOMILCON_DT = #FORM.IE_PMOMILCON_DT#/>
<cftry>
<cffile action = "upload"
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
<!--- <CFIF variables.FILENAME is "">
<CFLOCATION url="upload378.cfm?F378_ID=#FORM.F378_ID#&ERROR=You must select a file.&FMBIC_DT=#FORM.FMBIC_DT#&IE_PMO_DT=#FORM.IE_PMO_DT#&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">
</CFIF> --->
<cfdump var="#cfcatch#">
<cfabort showError="debugging">
</cfcatch>
</cftry> <cfdump var="#form#">
The error message now tells me the path, where the uploaded file is stored, isn't valid. It exists.
The value of the attribute destination, which is currently \xxxxxx\secure\Authorization\378Docs\, is invalid.
Do you need to see the whole error page?
Sorry for the crappy formatting. I still haven't figured out how to format the code with the line numbers. I did once, but can't seem to do it again.
Thank you.
Copy link to clipboard
Copied
To format code, click on the "Use advanced editor" link at the top, right of the input box, highlight the text to format, then click the >> button in the toolbar.
Does the value of newDest contain a drive letter or is it a UNC path?
Cheers
Eddie
Copy link to clipboard
Copied
UNC - \xxxxxx\secure\Authorization\378Docs\
The \xxxxxx is the root where the code resides and the directory to store the uploaded file.
Copy link to clipboard
Copied
Remember that when the server reports that it cannot access a location, it is the user account that the CF process is using that might have problems accessing an existing location.
As a debugging step, try adding the following code to verify that the server can see a file that you know exists:
<cfif fileExists(newDest & 'filename.ext')>
The file is visible to the server.
<cfelse>
The file is not visible to the server.
</cfif>
Cheers
Eddie
Copy link to clipboard
Copied
I plugged it in before and after the debug code and no change. I'm sure I didn't do it correctly.
Copy link to clipboard
Copied
When you say "no change" do you mean you are not seeing either of the "The file is..." messages displayed on the Web page?
Create a new, temporary page with the test code I recently posted.
Cheers
Eddie
Copy link to clipboard
Copied
I deleted everything but the test code and got the message The file is not visible to the server. I put the original file back and the same message came up. I missed it in the original error page. The variable newDest is assigned earlier in the page:
<CFOUTPUT> | |
<CFSET newDest = #authfileroot#&"378Docs\"/> |
</CFOUTPUT>
Which gives the correct location displayed in the error message. What am I not understanding?