• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

Getting Error: The form field "FileURL" did not contain a file

This is a basic update page with the ability to change the file uploaded, or just leave the current one, or use none at all.

action="upload"
                filefield="FileURL"
                destination="/u/web/users/research/tco/technologies/"
      nameconflict="MakeUnique"
      accept="application/*">
                <cfif FORM.FileURL NEQ "">
      <cfset FileURL = FILE.ClientFile>
      <cfelseif FORM.CurrentFile NEQ "">
      <cfset FileURL = #FORM.CurrentFile#>
      <cfelse>
      <cfset FileURL = 'None Assigned' >
      </cfif>
<cfquery datasource="vpr">
      UPDATE tcoLicensing
      SET
            Title='#FORM.Title#',
            Body='#FORM.Body#',
            FileURL = '#FileURL#'
            WHERE ID = '#FORM.ID#'
</cfquery>

Hopefully you can see what I am trying to do.  If a file field in "FileURL" exists, then use it, if not and something is in "CurrentFile", then use it, if neither of those, enter 'None Assigned'.  So, I need it to work, even when no file was entered.  

thanks experts!!!!
0
jhmoen
Asked:
jhmoen
3 Solutions
 
mkishlineCommented:
The form that's passing in the variables needs to have <form enctype="multipart/form-data">.  You will also need to change your check to this:

<cfif Form.FileUrl NEQ>
  <cffile action="upload" filefield="FileURL" destination="/u/web/users/research/tco/technologies/" nameconflict="MakeUnique" accept="application/*">
  <cfset FileURL = FILE.ClientFile>
  <cfelseif FORM.CurrentFile NEQ "">
  <cfset FileURL = #FORM.CurrentFile#>
<cfelse>
  <cfset FileURL = 'None Assigned' />
</cfif>
0
 
digicidalCommented:
mkishline, your first conditional statement should read
<cfif Form.FileUrl NEQ ""> NOT <cfif Form.FileUrl NEQ> correct?

As an added tip, when checking for a blank field it is usually a better practice to use the following:
<cfif Len(Trim(Form.FileUrl)) GT 0>

I believe this is because string content comparisons take slightly longer to process in the Java compiler than a simple string length does... but I'm not sure.  The one thing I know it does is prevent the accidental " " instead of "" being used. (I've done that to myself a couple of times before and I've seen dozens of examples that have done it as well).
0
 
JeffHowdenCommented:
It's always good to note that <cfif Len(Trim(form.fileurl)) GT 0> is long-hand for the more succinct (and fewer comparison operations) version <cfif NOT Len(Trim(form.fileurl))>.
0
 
digicidalCommented:
Good point... although in Java (since that's actually what CF is) there shouldn't be a difference between a boolean NOT and a arithmatic GT or LT or EQ/NEQ for that matter.  Only multistep math comparisons would require an extra cycle (i.e. GTE or LTE).  

All basic math functions on any modern language should be one tick returns (+,-,*,/,<,>,=,!=,etc..)  Regardless you are correct about it being more succinct.  I don't know if you've had any experience with it, but I've also heard that contrary validations take 1 more cycle than agreeing validations (i.e. 'if NOT X' will take one tick more than 'if X').  Have you observed any difference in this?

However you made an error in your example (although your point is entirely valid).

<cfif Len(Trim(form.fileurl)) GT 0> is the same as <cfif Len(Trim(form.fileurl))>,
and
<cfif Len(Trim(form.fileurl)) EQ 0> is the same as <cfif NOT Len(Trim(form.fileurl))>.

Using <cfif Len(Trim(form.fileurl))> in this case is better than my example because it neither uses a NOT operator nor does it use an Arithmatic operator GT (although it still does in the compiled state because of the way CFIF is translated into java bytecode as far as I can tell).

Anyway, it's only going to matter on a very large application, and any of them will 'work' for you JHMOEN, but it's good to write tight code from the beginning because you never know.  I have one application that began as a simple document storage and retrieval system, but is now about 20K lines of code in 9 components and about 300 templates... If I'd known what kind of monster it would become I'd have definitely researched ways of optimizing code prior to starting... it's easier to start correctly than to have to retrofit something monstrous!

Good luck JHMOEN...
0
 
jhmoenAuthor Commented:
Increased the points, I would like to award all three of you for your insight.
This was great, and has shed some light on better ways of doing the same thing...which I appreciate.

Thanks mkishline, digicidal, and JeffHowden!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now