3 Replies Latest reply on Mar 7, 2007 9:41 AM by Newsgroup_User

    Issue with CFUpload and CFCs

    Jason_the_Mullerite
      I have the following two methods in the same cfc:

      This function is used to generate the upload form...
      <cffunction name="uploadPictureView" hint="Form to upload bio picture" access="remote">
      <form name="uploadForm" action="cmsBios.cfc?method=uploadPicture" enctype="multipart/form-data">
      Please Select Bio Photo<br>
      <input type="file" name="UploadFile">
      <input type="submit" value=" Upload File ">
      </form>
      </cffunction>

      This function is used to upload the file to the directory and then close the popup and refresh the base page...
      <cffunction name="uploadPicture" hint="Script to upload bio picture" description="Upload Picture" access="remote" output="false">
      <cfset uploadPath = #APPLICATION.localPath# & "\images\bioPicts\">
      <cfif not DirectoryExists(uploadPath)>
      <cfdirectory action="create" directory="#uploadPath#">
      </cfif>
      <cffile action="upload" fileField="UploadFile" destination="#uploadPath#" nameConflict="MakeUnique">
      <script>
      refreshParent();
      </script>
      </cffunction>

      The file does not get uploaded and instead it loads a description of the cfc and all the methods. No error so I can't tell what is wrong. How do I get this to work? Anyone have any ideas?

      Thanks,

      Jason
        • 1. Re: Issue with CFUpload and CFCs
          Level 7
          The file does not get uploaded and instead it loads a description of the
          cfc and all the methods. No error so I can't tell what is wrong. How
          do I get this to work? Anyone have any ideas?


          If you are getting the description of the CFC and it's methods, then CF
          is running the Component Explorer, which is the default behavior if one
          access a CFC directly with an URL.

          When I use a CFC as an action for a post form, I put the method in as a
          hidden field rather then an URL parameter. You could give that a try.

          <input type="hidden" name="method" value="uploadPicture">


          • 2. Re: Issue with CFUpload and CFCs
            Jason_the_Mullerite Level 1
            I removed the ?method=uploadPicture from the action attribute and added the hidden variable but now I am getting this message:

            Invalid content type: "".

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

            The error occurred in D:\www\CMS\CFCs\cmsBios.cfc: line 511

            509 : <cfdirectory action="create" directory="#uploadPath#">
            510 : </cfif>
            511 : <cffile action="upload" fileField="UploadFile" destination="#uploadPath#" nameConflict="MakeUnique">
            512 : <script>
            513 : refreshParent();

            I have the enctype set to multipart/form-data. Also does the cfc know which method to use automatically from the hidden variable or do I need to specify that some how?

            Thanks
            • 3. Re: Issue with CFUpload and CFCs
              Level 7
              Also does the cfc know which method to use automatically from the hidden
              variable or do I need to specify that some how?

              You have to specify the method you want to use as the value of the
              hidden field.

              <input type="hidden" name="method" value="methodName">

              Look at the source of the form being generated by your code. Is it
              properly formated? Is there a chance that somehow the output is mangled
              so that you are not getting a correct form?