Skip to main content
January 21, 2011
Question

Issue with Content type using <cfform> or <form> and <cffile>

  • January 21, 2011
  • 2 replies
  • 1933 views

I'm receiving the below error whenever i attempt to upload a file.

Invalid content type: ''.

The cffile action="upload" requires forms to use enctype="multipart/form-data".

I'm using <cfform> and have the enctype="Multipart/form-data".

If i do not have a enctype ColdFusion states that the default enctype is incorrect.

I tried using <form> but experienced the same issue.

My <cfform> is in an include and is as follows:                    

---------------

      <cfform enctype="multipart/form-data" name="qb_email" action="OA_util_rpt3.cfm?List=#url.list#&t=#url.t#" method="POST" onsubmit="return FormCheck(this)">

---------------   

My cffile is also in the same include where i have checks to make sure everything is entered correctly and a different path for the file uploading:
----------------
       <cffile action="upload" filefield="Attachments" destination="#TRIM(batch_dir)#"  nameconflict="overwrite">
----------------
Destination is present and starts with C:
Attachments is present.

Anyone have any ideas as to why i'm getting this error when i do in fact have enctype defined. I have this exact same code in several other pages and everywhere else it works fine. However, this is the only one where i go from a folder back to main directory, then to another folder for the include, and then back to main directory and then to batch to upload file.

Another interesting thing is the file is uploaded into my Batch folder but i get the message, and if i go back to the page, the file is listed and will be attached to my email as intended.

Thanks,

Daniel

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    January 21, 2011

    Like Dave, I suspect it's got to do with the onSubmit. It seems that the Javascript call changes the enctype to a blank. What if you do something like this

    onsubmit="return FormCheck(this); return true;"

    January 21, 2011

    Rough code for for <cfform> i removed the onsubmit and the issue still exists.

    -----------

    <cfform enctype="multipart/form-data" name="qb_email" action="OA_util_rpt3.cfm?List=#url.list#&t=#url.t#" method="POST">

    <cfinput type="text" name="Subject" size="35" value='' required="yes" message="Please enter a subject.">
      <CFTEXTAREA height="300" richtext="yes" name="msg" required="yes" message="Please enter a message."> </cftextarea>
    <input type="file" name="Attachments" size="40"><input type="Submit" name="attach" value="Attach File">
    <input type="Submit" name="Submit" value=" Send ">
    </cfform>
    -----------
    rough code for <cffile>
    -----------
    <cffile action="upload" filefield="Attachments" destination="#TRIM(batch_dir)#"  nameconflict="overwrite">
    -----------
    This is all in the same include with conditions to check whether the user has enter in data in the form and everything else. All the code works fine except when attempting to use <cffile> i have used <cfform> and <form> with and without onsubmit and received the same error message. The file does upload to the Batch_dir location however, there is the error so the page crashes. When i reload the page, the file is 'attached' and uploaded and when i send the email everything arrives.

    I'm attempting to write an email include that will allow me to plug in this email with attachments anywhere i want. I have this exact same code. In about 10 different places and all of them work.

    Community Expert
    January 21, 2011

    Try commenting out the CFTEXTAREA, or setting the RICHTEXT attribute to "no".

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    Community Expert
    January 21, 2011

    What's happening in the form's onsubmit event handler?

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    January 21, 2011

    I removed the onsubmit and still have the same issue.

    What this is doing is sending an email and if i don't attach a file it works fine. It only happens when attaching a file.

    Thanks For looking into this...

    Daniel

    Community Expert
    January 21, 2011

    Maybe you should post the form and action page(s) in their entirety.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC