Skip to main content
March 1, 2016
Answered

Error uploading a file

  • March 1, 2016
  • 6 replies
  • 13619 views

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>


This topic has been closed for replies.
Correct answer BKBK

Why do you now bring in "the .cfm file that does the pop-up; where the error occurs"? Weren't we talking instead about the CFM file that does the upload, where the error occurs?

Insert the test code in the file that does the upload. (I would temporarily comment out the upload code first).

My apologies...   the pop-up and the upload are the same file.  So, I did as you said and the current directory and the directory that is supposedly invalid are identical.  Sorry for the confusion.


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 of the destination is

\\wedt-Dev\secure\Authorization\378Docs\

whereas the upload form's action page (which you have blanked out) is at

\\W...\...\...\WEDT\secure\Authorization\upload378Act.cfm

The respective root directories are different. This suggests that the paths \\wedt-Dev\secure\Authorization\ and \W...\...\...\WEDT\secure\Authorization\ belong to 2 different environments, possibly development and production. In fact, the latest error message suggests you're attempting to get the production code (in \WEDT\secure\Authorization\) to upload files to a destination on the development server (in \WEDT-DEV\secure\Authorization\).

Now, on to a possible solution. Use the following dynamic, server-independent definition of your destination directory

<cfset newDest = getDirectoryFromPath(expandpath('*.*')) & "378Docs\">

Place the line just before the cffile upload tag. It will resolve to

\\wedt-Dev\secure\Authorization\378Docs\

or to

\\W...\...\...\WEDT\secure\Authorization\378Docs\

depending on which server you are on.

6 replies

July 26, 2016

Ok stupid question time...  since the file is being uploaded to a subdirectory where the code resides, is there a way to do something like a directory listing to show what it thinks is there so I can compare it to what I am trying to assign?   I know I'm grasping at straws, but I have not much else.   Thank you.

BKBK
Community Expert
Community Expert
July 26, 2016

<!--- The result is a query --->

<cfdirectory directory="full_path_to_directory" name="dirQuery" action="list">

<cfdump var="#dirQuery#">

<!--- Query of the query. Perhaps more useful, containing just what you need --->

<!---

<cfquery name="dirQuery2" dbtype="query">

SELECT name, dateLastModified, size, type

FROM dirQuery

</cfquery>

<cfdump var="#dirQuery2#">

--->

July 29, 2016

I inserted the 1st one in the .cfm file that does the pop-up; where the error occurs.  The directory shown by that code and the one the error message says is invalid, are identical.   So, what is invalid about the directory that exists?   Is there a way to get more detail?   So confused.

Carl Von Stetten
Legend
July 18, 2016

Louie,

You are correct.  I think I had this confused with another thread (maybe not even one from you) that kept changing topic.  Nevermind.

-Carl V. - Moderator

July 19, 2016

I think my post from July 1 is where things went astray.   While it's the same application, it has nothing to do with the original error.  As I said earlier, I tend to react to errors I have and not think it through whether it fits in the thread or not.  I will do my best to not do that any more on here.

Known Participant
May 17, 2016

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

EddieLotter
Inspiring
May 17, 2016

Good thought, but he already has that.

Cheers

Eddie

Known Participant
May 17, 2016

Hmm, OK.  I searched this page and didn't see it.

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

WolfShade
Legend
March 1, 2016

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,

^_^

March 17, 2016

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>

EddieLotter
Inspiring
March 17, 2016

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

BKBK
Community Expert
Community Expert
March 1, 2016

Just


  <cffile action = "upload"  

             fileField = "requiredFILENAME"  

             destination = "#newDest#"     

             accept = "application/pdf">


and Coldfusion will tell you what the matter is.

EddieLotter
Inspiring
March 1, 2016

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