Search code examples
linuxformscoldfusionenctype

ColdFusion/Linux multipart/form-data encoding file upload issue


I'm posting a form in ColdFusion on Linux. Form has a file field. CF requires the enctype="multipart/form-data" attribute on the form tag. If I have this, I get a "JRun Servlet Error - 500 No such file or directory"

If I take the attrib out, the form posts and I get the CF "enctype=multipart/form-data" error.

What to do?

Here's a stripped version of the form:

 <form action="post.cfm" name="form2" id="port_form" method="post" enctype="multipart/form-data">
      <input type="text" id="name" name="name" value="#port_name#"><br>
      <input type="file" id="before" name="before"><br>
      <input type="hidden" name="port_id" value="#port_id#" />
      <button type="submit" name="post"> Post Portfolio Item </button>  
 </form>

Here's the page I'm posting to (post.cfm)

 <cfif form.before neq "">
    <cfinvoke component = "#application.cfcPath#.file" method = "upload" returnVariable = "beforeFile" theField="before">
 <cfelse>
    <cfset beforeFile = ''>
 </cfif>

 <cfif form.after neq "">
    <cfinvoke component = "#application.cfcPath#.file" method = "upload" returnVariable = "afterFile" theField="after">
 <cfelse>
    <cfset afterFile = ''>
 </cfif>    

 <cfinvoke component = "#application.cfcPath#.portfolio" method = "post" beforeFile="#beforeFile#" afterFile="#afterFile#">

 <cfif form.port_id eq 0>
    <cfset message = "The Portfolio Item has been successfully inserted.">
 <cfelse>
    <cfset message = "The Portfolio Item has been successfully updated.">
 </cfif>

 <cf_forward fuseaction="#fusebox.circuit#.home" message="#message#">

Solution

  • Possible reason is that server can not find the uploaded temp file.

    Have you tried to make upload without component wrapper?

    Simply

    <cfif StructKeyExists(Form, "before") AND Form.before NEQ "">
    <cffile
        action="upload"
        filefield="before"
        destination="#AbsPathToStoreFile#"
        >
    </cfif>
    
    <cfdump var="#cffile#">
    

    If this fails maybe you'll be able to see more details.