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

Posted on 2006-03-28
Last Modified: 2013-12-24
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.

                <cfif FORM.FileURL NEQ "">
      <cfset FileURL = FILE.ClientFile>
      <cfelseif FORM.CurrentFile NEQ "">
      <cfset FileURL = #FORM.CurrentFile#>
      <cfset FileURL = 'None Assigned' >
<cfquery datasource="vpr">
      UPDATE tcoLicensing
            FileURL = '#FileURL#'
            WHERE ID = '#FORM.ID#'

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!!!!
Question by:jhmoen
    LVL 12

    Accepted Solution

    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#>
      <cfset FileURL = 'None Assigned' />
    LVL 9

    Assisted Solution

    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).
    LVL 7

    Assisted Solution

    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))>.
    LVL 9

    Expert Comment

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

    Author Comment

    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!

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    A web service ( is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
    Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now