5 Replies Latest reply on Nov 29, 2006 1:43 PM by shaunperry

    CFFILE Upload question

    Kyle.Hayes
      I have a question and I believe I know the answer but I want to ping all of you to see what you say. I am developing an application using Mach-II. I would like to upload a file. I have no problem seeing the filefield in my listener. Technically I could just process the cffile action="upload" right there in the listener, but instead I would like to stick to convention and upload it in my FileService component instead. Is there a way of passing the form file field to the service and then processing the upload?

      I have a feeling based on the way that CFFILE is built this is not possible. Please advise. I will be happy to resolve any confusion my message may have.
        • 1. Re: CFFILE Upload question
          hatethisnamegame Level 1
          Don't know about Mach II but passing to a cfc is as follows:
          <cfinvoke component="somecfc" method="fileUpLoad" fileField="nameOfFileInput">

          The value passed in the fileField variable is the actual name of the input type="file"
          • 2. Re: CFFILE Upload question
            Kyle.Hayes Level 1
            I keep getting "backupDoc" does not contain a file, yet when I dump it, it displays the location to the temporary file. Then I have also run a FileExists on it and it does exist.
            • 3. Re: CFFILE Upload question
              Abinidi Level 1
              Post your code and we can see if we see something
              • 4. Re: CFFILE Upload question
                Kyle.Hayes Level 1
                My question has been answered by Brian Rinaldi over at Remote Synthesis ( http://www.remotesynthesis.com/blog). He wrote an article on how to deal with uploads via Model-Glue. He was able to clarify his post for me and now I understand what you have to do.

                What it comes down to is that you have to submit the name of the fileField in a hidden input field (for lack of a better way at this time) and pass that through your methods rather than the value of your fileField.
                • 5. CFFILE Upload question
                  shaunperry
                  Hi

                  I m having trouble with a similar project. I have a form which allows the user to choose a maximum of 3 upload fields. I have a filesystem.cfc file which handles the upload. the cfc code is below:

                  <cffunction name="upload" access="public" output="false" returntype="struct">
                  <cfargument name="formFieldName" required="true" type="string" />
                  <cfset var stReturn = structNew() />
                  <cfset var stFileUpload = "" />
                  <cffile action="upload" filefield="formFieldName" destination="#variables.destination#" nameconflict="makeunique" result="stFileUpload" />

                  <cfset stReturn.success = true />
                  <cfset stReturn.sourceFile = stFileUpload.serverFile />
                  <cfreturn stReturn />
                  </cffunction>

                  when the user submits the form I use the following code is processed:

                  <!--- loop through fields --->
                  <cfloop from="1" to="#num#" index="counter">
                  <cfset fileUpload = fileSystem.upload(formfieldName=FORM["file"&counter]) />
                  </cfloop>

                  but i get the error message "The form field "formFieldName" did not contain a file".

                  any help or advice is appreciated, I had a look at Brian Rinaldis blog but its not too clear to me how it works.

                  regards

                  shaun