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
Yes, but every other upload of files done in this application, use the same code, the same directory references, and all, and they work correctly now, every time. Why would this be any different?
Copy link to clipboard
Copied
When I run the original code, I just get a generic error message that the file was unable to be uploaded. Nothing else shows up on the debug screen. When I comment out the error message section and enter the abort code as mentioned earlier in the thread I get this:
Copy link to clipboard
Copied
Reviewing the code, it dawned on me that things may have changed with me making changes. I went to the archive where I have the original code, that worked up until earlier this year. I didn't see anything different than what was up there, except the part where I had entered the debug/abort stuff recommended earlier. Since I am not that well versed in CF, is there anything obviously wrong with this code?
<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 don't really understand how this got here to produce the error message.
Thank you all, once again, for all your assistance. Definitely getting an education...
Copy link to clipboard
Copied
#newDest# should be contained within double quotes (")..
^_^
Copy link to clipboard
Copied
#newDest# should be contained within double quotes (").
Did that and it didn't make a difference... then again, I didn't dump the variable to see if it was correct.
Just so I don't misunderstand, any variable assignment should be
"#variable#"
and not just #variable"? In concatenations it should be
"#variableORstring1#"&"#variableORstring2#"
Is that correct?
Copy link to clipboard
Copied
When referencing a variable, the only time the hashtags are used are:
1) when the variable is being referenced as part of a string, like "This is the value of myVar: #myVar#", or some such.
2) when the variable is being directly output to the page, like <cfoutput>This is freetexting in the page: #myVar#</cfoutput>
Any other time, like if you're contatenating values without putting them in strings (chr(13) & chr(10) is a line break carriage return), or evaluating something (ListFindNoCase(myList,"foobar")), you don't use hashtags because that can actually slow down processing the data.
So, attributes of tags are contained within quotes (aka, a string) - destination="#newDest#", not destination=#newDest#.
Let's say that the value of newDest is "Orlando". In the first example, CF interprets attribute="value", or destination="Orlando". In the second example, CF interprets attribute=variable, or destination={a variable called Orlando, which doesn't exist}. I've seen code like destination=newDest, but that's hokey and not reliable.
HTH,
^_^
Copy link to clipboard
Copied
Just a thought, what if you added enctype="multipart/form-data" to the form?
Copy link to clipboard
Copied
Good thought, but he already has that.
Cheers
Eddie
Copy link to clipboard
Copied
Hmm, OK. I searched this page and didn't see it.
That's all I had to offer, good luck.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
<!--- 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#">
--->
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
LouieWarren wrote:
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.
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).
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I believe the discrepancy is my absent minded self not putting things up correctly. My customer gets weird when I put actual directories and application names, etc. In my haste to solve this issue I changed more of the directory name in one than I did in the other. All that aside, it appears your fix, fixed it! I have to do some more testing, but I believe we have finally fixed this pig! Thank you.
Should I wait until I actually verify things are working to mark this as solved, or do it now?
Copy link to clipboard
Copied
At your convenience, LouieWarren. The important thing is that you're satisfied your problem is solved.