1 2 3 Previous Next 93 Replies Latest reply on Aug 10, 2016 12:18 PM by BKBK

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>

fileField = "requiredFILENAME"

destination = #newDest#

accept = "application/pdf">

<cfcatch>

&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">

</cfcatch>

</cftry>

To get more details, temporarily try the following:

<cftry>
fileField = "requiredFILENAME"
destination = #newDest#
accept = "application/pdf">
<cfcatch>
&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

Just

fileField = "requiredFILENAME"

destination = "#newDest#"

accept = "application/pdf">

and Coldfusion will tell you what the matter is.

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,

^_^

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>

fileField = "requiredFILENAME"

destination = #newDest#

accept = "application/pdf">

<cfcatch>

&IE_PMOMILCON_DT=#form.IE_PMOMILCON_DT#">

<!---  <cfdump var="#cfcatch#">

<cfabort showError="debugging"> --->

</cfcatch>

</cftry>

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

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.

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>

fileField = "requiredFILENAME"

destination = #newDest#

accept = "application/pdf">

<cfcatch>

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

fileField = "requiredFILENAME"

destination = #newDest#

accept = "application/pdf">

<cfcatch>

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?

500 Internal server error

Then something went wrong with the form submission. Could you share the form page with the forum?

I am a CF novice.  I hope I've included the right part of the code.   Here's the entire calling .cfm file:

<HTML>

<BODY>

<!--- <CFOUTPUT>#CGI.QUERY_STRING#</CFOUTPUT> --->

<CFOUTPUT>

<CFSET newDest = #authfileroot#&"378Docs\">

</CFOUTPUT>

<CFQUERY datasource="#datasource#" name="Getdata">

where F378_ID=#FORM.F378_ID#

</CFQUERY>

<cfoutput>

</cfoutput>

<cfif fileexists("#oldfile#")>

<cftry>

<cffile action = "delete" file=#oldfile#>

<cfcatch>

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

fileField = "requiredFILENAME"

destination = #newDest#

accept = "application/pdf">

<cfcatch>

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

</cfcatch>

</cftry>

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'),

where F378_ID=#FORM.F378_ID#

</CFQUERY>

<script language=javascript type='text/javascript'>

//opener.window.location=opener.window.location;

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.

That was the action page. I requested the form page.

In any case, you could do with fewer <cfoutput> tags and fewer # symbols:

<HTML>

<BODY>

<!--- <CFOUTPUT>#CGI.QUERY_STRING#</CFOUTPUT> --->

<CFSET newDest = authfileroot & "378Docs\">

<CFQUERY datasource="#datasource#" name="Getdata">

where F378_ID=#FORM.F378_ID#

</CFQUERY>

<cfif fileexists("#oldfile#")>

<cftry>

<cffile action = "delete" file="#oldfile#">

<cfcatch>

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

fileField = "requiredFILENAME"

destination = "#newDest#"

accept = "application/pdf">

<cfcatch>

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

</cfcatch>

</cftry>

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'),

where F378_ID=#FORM.F378_ID#

</CFQUERY>

<script language=javascript type='text/javascript'>

//opener.window.location=opener.window.location;

self.close();

//return false;

</SCRIPT>

<CFELSE>

How did you get here!!!

<script language=javascript type='text/javascript'>

self.close();

</SCRIPT>

</CFIF>

</BODY>

</HTML>

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.

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;">
</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">
<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>


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.

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

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.

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

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>

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_PMOMIL CON_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.

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

Just a thought, what if you added enctype="multipart/form-data" to the form?

Good thought, but he already has that.

Cheers

Eddie

That's all I had to offer, good luck.

UNC  - \xxxxxx\secure\Authorization\378Docs\

The \xxxxxx is the root where the code resides and the directory to store the uploaded file.

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

I plugged it in before and after the debug code and no change.  I'm sure I didn't do it correctly.

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

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>

Which gives the correct location displayed in the error message.  What am I not understanding?

It's time to get your network administrator involved. And the server administrator if they are not the same person.

If ColdFusion cannot access a file, that you know to exist, then the user account that the ColdFusion service is using, doesn't have the necessary security privileges to access that folder. Only your administrator(s) can sort out security problems.

Cheers

Eddie

I've had the SysAdmin involved and he ensures me (with screen shots) that everything is correct and that it is my problem.  I had another error with this app, earlier, where it was trying to produce a report (an Excel spreadsheet) and it threw the error message, "access denied".  I was able to go to the directory in FTP and change the permissions to 777 and it worked.  I will attempt that with this, but I don't see how it would change the not found issue.

It occurs to me that you said it is a UNC path, but you aren't showing the initial double-backslash in your posts. You are using one in your code, right?

For example: \\MachineName\folder\subfolder\file.ext

Cheers

Eddie

Ok, it's highly likely I misunderstood UNC...

The directory is assigned in Application.cfc

<cfset authfileroot="\xxxxxxxx\secure\Authorization\">


In the .cfm I am working with, the storage location of the uploaded file is assigned as such:

<CFOUTPUT>
<CFSET newDest = #authfileroot#&"378Docs\"/>
</CFOUTPUT>


Yes, that makes more sense.

You are not specifying which drive the folder is on.

Is it a local hard drive on the server or is it a network share?

If it is a local hard drive, then add the drive letter (like C: or D:) however, if it is a network share, then use a UNC path, which your SysAdmin can give you.

Cheers

Eddie

I believe it's a local drive.  It's the same drive that contains the CF code.  When you select the option to upload the file, you are in the same directory where the code for that option resides.  There is a subdirectory that is defined (as mentioned earlier) where the physical uploaded file resides and a link to that file is stored in the database.

The biggest issue I have is, 1) it worked flawlessly up until a little while ago (beginning of this thread)  2) the gov't sysadmin says that nothing has been done to change directories or permissions  3) there are no references to drive letters in any part of the code.  The way I get it in my simple mind is, when you log in, you are virtually logging in as the schema/user for the database and all the files and database are yours to update as the application allows.  What would have caused this to suddenly change after working fine for a while?  Newer version of Windows?  CF?  Supposedly my development server, the Test server, and the Production server are all running the same version of Windows, CF, and Oracle.   The original code was written with CF 8 and I believe we're at 11 now.  I found a few things that caused me issues between the old and new versions of CF (i.e.- getbuiltin scopes), but nothing like this.

If you don't provide an explicit path, ColdFusion will rely on the Windows process' "current directory" when using the <cffile> tag, which differs from tags like <cfinclude> where CF uses the current script's folder as the "current directory."

The current directory of a Windows process is complicated and fragile. It's best to be explicit by using a full path including the drive, even if it doesn't fix your current problem.

I can't answer your questions as to why your script no longer works, but using an explicit path will rule out the unexpected results of the current directory not being what you expect it to be.

Cheers

Eddie

The only explicit path in all the code is

\\servername\test\sites\codebase  directory structure


The Gov't SysAdmins are running 50 or so applications/databases on a VMWare Server.  They have said they can't (won't) give me a more explicit path.  So I guess I am screwed.   The biggest issue I have at present is why it couldn't upload the file.  Just the generic message: We were unable to upload your file. Please try again..

I have CF Admin debugging on and don't see anything significant.   Trying again just gives the same error.  At first I thought it was due to special characters in the filename and changed the file name to eliminate special characters and embedded blanks.  No change.  Really baffled.

CFTRY/CFCATCH/CFDUMP will at least alert you to the issue, with specifics.  I just now noticed in your first post that there already is a CFTRY/CFCATCH, but all it is doing is redirecting to another page with a lot of URL parameters, one of which is the error message text.  If you were to put a CFMAIL (type="html") with a CFDUMP of the #cfcatch# variable, you should see what is triggering the error.

As far as I know, you cannot use "\\servername\path\to\upload\" for cffile uploads.  If you use a relative path (ie, "/path/to/folder/") then CF will use that in relation to the CF temp folder, which resides within CFIDE, I think.  You must use something like "F:/path/to/folder/".  Unless you're in a unix/linux environment.  (NOTE:  If you can use a URL as a location, you'll have to use CFFTP to FTP the file - CFFILE does not work across servers.)

If the sysadmins will not assign a full physical drive path, then tell them that the only alternative is to store the files in the database.  The upside to this is that if you ever have to delete one, you just delete it in the database, as opposed to deleting the reference from the database AND using cffile action="delete" to remove the binary, itself.  The downsides are A) depending upon the file sizes, you could bloat the database; and B) if the site/app has over a certain number of users, this will bottleneck your network.  (Third edit: If space on the webserver is an issue, there's always SAN storage.)

HTH,

^_^

That "generic" message is coming from the code that you quoted in your very first post here. It is not a ColdFusion message. We asked you to temporarily remove that line of code because it is masking the ColdFusion message.

Please do so and then let us know what message ColdFusion is giving you.

Cheers

Eddie

With all the things that are wrong with this mess I inherited, I skipped over your comment.  My apologies.

I did as you suggested and ended up having to completely delete the error message because, even commented out it still gave me the message.  I copied the file and made changes to the new one.  Loaded it up to the directory and got this message:

The value of the attribute destination, which is currently \TestServer\secure\Authorization\378Docs\, is invalid.

I checked the directories in the FTP tool I use to upload and the directory is there and it is spelled correctly.   No clue what to do with this.