4 Replies Latest reply on Jun 7, 2009 2:08 PM by Toadsteraz

    POSTvariable Problem

    Toadsteraz

      I was looking at the MultiFileUploade article done by Ryan Farvo on the Adobe website.

      http://www.adobe.com/devnet/coldfusion/articles/multifile_upload.html

       

      He mentions that you can send POST Variables to the server which I am assuming would be custom variables for us to use like sending data to a database.

       

      As he states:

      "URLVariables: This is a variable with a URLVariables data type that contains any additional variables to be passed to the server for processing. The sample application shows two sample variables: postVariables.projectID = 55 and postVariables.test = "Hello World""

      So how would I access these? For example I use the following in my Flex Action Script file:

      var

       

       

      postVariables:URLVariables = new URLVariables;

      postVariables.newsID = news_id;

       

      So when the data is sent to upload.cfm I use a query to store the file name into a database along with my news_id.

       

       

       

       

       

       

      <cfquery

       

       

       

      name="AddImages"

      datasource=#website_database#>

       

       

       

      INSERT INTO

      news_images (news_index, image)

       

       

       

      VALUES

      (

       

       

      '#URL.newsID#'

      ,

       

       

       

      '#File.ServerFile#'

      )

       

       

       

      </cfquery>

       

      The File.ServerFile works fine, I get the file name however the new_id doesnt come through? Is it not a #URL.Variable#? What do I call out to get my id number?

       

      Thank you for your help!

      Todd

       

       

        • 1. Re: POSTvariable Problem
          crumsberry

          You should use your debugging feature to find if "postVariables.newsID" even has a value and what the value of the "news_id" variable is after it has been assigned. Then just before and after it is loaded by the cfquery.

          Plus changing from newsID to news_id then to news_index is a little confusing. Keep your variable constant as much as you can so you don't have to remember every single one as it changes form.

           

          Smile

          • 2. Re: POSTvariable Problem
            Toadsteraz Level 1

            OK let me do this! Attached is my code, still getting a problem!

             

            [FlexFileUpload.mxml]

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:TitleWindow

             

             

            xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="initApp();" borderAlpha="1.0" showCloseButton="true" close="PopUpManager.removePopUp(this);" title="Image Upload Control" fontFamily="Calibri" fontSize="12" fontWeight="normal" color="#000000"

            >

             

             

             

             

             

            <mx:Script source="FlexFileUpload_cb.as"/>

             

             

             

             

            <mx:Panel width="652" height="330" layout="absolute" color="#000000" fontFamily="Calibri" fontSize="12">

             

             

             

             

            <mx:DataGrid id="filesDG" left="0" right="0" bottom="30" top="5"/>

             

             

             

            <mx:ProgressBar id="progressbar" labelPlacement="center" trackHeight="15" left="0" right="0" bottom="5" height="20"/>

             

             

             

             

            <mx:ControlBar>

             

             

             

             

            <mx:Spacer width="100%"/>

             

             

             

            <mx:HBox>

             

             

             

            <mx:Button label="Browse For Files" id="browseBTN"/>

             

             

             

            <mx:Button label="Upload" id="upload_btn"/>

             

             

             

            <mx:Button label="Remove" id="delButton"/>

             

             

             

            <mx:Button label="Clear All" id="clearButton"/>

             

             

             

            </mx:HBox>

             

             

             

             

            </mx:ControlBar>

             

             

             

             

            </mx:Panel>

             

            </mx:TitleWindow>

             

            [FlexFileUpload_cb.as]

             

            // Code Behind for FlexFileUpload.mxml

             

              

             

            import com.newmediateam.fileIO.MultiFileUpload;

             

             

            import flash.media.SoundChannel;

             

            import flash.net.FileFilter;

             

             

            import mx.core.SoundAsset;

             

             

            public var multiFileUpload:MultiFileUpload;

             

             

            import mx.managers.PopUpManager;

             

             

            // Sound to play when all files complete uploading

            [

            Embed(source="assets/audio/Ding.mp3")]

             

            public var soundClass:Class;

             

            public var snd:SoundAsset = new soundClass() as SoundAsset;

             

            public var sndChannel:SoundChannel;

             

             

            // Set the File Filters you wish to impose on the applicaton

             

            public var imageTypes:FileFilter = new FileFilter("Images (*.jpg; *.jpeg; *.gif; *.png)" ,"*.jpg; *.jpeg; *.gif; *.png");

             

            public var videoTypes:FileFilter = new FileFilter("Flash Video Files (*.flv)","*.flv");

             

            public var documentTypes:FileFilter = new FileFilter("Documents (*.pdf), (*.doc), (*.rtf), (*.txt)",("*.pdf; *.doc; *.rtf, *.txt"));

             

             

            // Place File Filters into the Array that is passed to the MultiFileUpload instance

             

            public var filesToFilter:Array = new Array(imageTypes,videoTypes,documentTypes);

             

             

            public var uploadDestination:String = "assets/cfcs/upload.cfm"; // Modify this variable to match the URL of your site

             

             

            public function initApp():void{

             

             

            var postVariables:URLVariables = new URLVariables;

            postVariables.news_ID = newsID;

             

            //postVariables.test ="Hello World";

             

            multiFileUpload =

            new MultiFileUpload(

            filesDG,

            browseBTN,

            clearButton,

            delButton,

            upload_btn,

            progressbar,

            uploadDestination,

            postVariables,

            3500000,

            filesToFilter

            );

             

            multiFileUpload.addEventListener(Event.COMPLETE,uploadsfinished);

             

            }

             

            [

            Bindable] private var news_ID:int;

             

            import mx.controls.Alert;

             

             

            public function load_vars(n_id:int):void {

            news_ID = n_id;   //THIS IS RUN AT LOAD, i.e. ALERT SHOWS ME 6

            Alert.show(String(news_id));

            }

             

             

            public function uploadsfinished(event:Event):void{

             

            sndChannel=snd.play();

             

            }

             

            [upload.cfm]

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

              

            <!---

            Flex Multi-File Upload Server Side File Handler

             

            This file is where the upload action from the Flex Multi-File Upload UI points.

            This is the handler the server side half of the upload process.

            --->

             

              

            <cftry>

             

             

             

            <cfset strPath = #GetDirectoryFromPath(GetCurrentTemplatePath()).ReplaceFirst("([^\\\/]+[\\\/]){1}$", "")#

            >

             

             

            <cfset imagePath = strPath & "images\news_images\"

            >

             

             

             

            <cfset req = getHTTPRequestData( )

            >

             

            <!---

            Because flash uploads all files with a binary mime type ("application/ocet-stream") we cannot set cffile to accept specfic mime types.

            The workaround is to check the file type after it arrives on the server and if it is non desireable delete it.

            --->

             

             

            <cffile action="upload"

             

             

            filefield="filedata"

             

             

            destination="#imagePath#"

             

             

            nameconflict="makeunique"

             

             

            accept="application/octet-stream"

            />

             

             

             

            <!--- Begin checking the file extension of uploaded files --->

             

             

            <cfset acceptedFileExtensions = "jpg,jpeg,gif,png,pdf,flv,txt,doc,rtf"

            />

             

             

            <cfset filecheck = listFindNoCase(acceptedFileExtensions,File.ServerFileExt)

            />

             

            <!---

            If the variable filecheck equals false delete the uploaded file immediatley as it does not match the desired file types

            --->

             

             

            <cfif filecheck eq false

            >

             

             

            <cffile action="delete" file="#imagePath##File.ServerFile#"

            />

             

             

            <cfelse>

             

             

            </cfif>

             

             

             

            <!-- CONFIG FILE - JUST USED TO ASSIGN MY DATABASE -->

             

             

            <cfinclude template = "config.cfm"

            >

             

             

             

            <cfquery name="AddImages"

            datasource=#website_database#>

             

             

            INSERT INTO

            news_images (news_ID, image)

             

             

             

            VALUES

            (

             

             

            '#cfhttp.news_ID#'

            ,

             

             

            '#File.ServerFile#'

            )

             

             

            </cfquery>

             

             

             

             

            <!---

            Should any error occur output a pdf with all the details.

            It is difficult to debug an error from this file because no debug information is

            diplayed on page as its called from within the Flash UI. If your files are not uploading check

            to see if an errordebug.pdf has been generated.

            --->

             

             

            <cfcatch type="any"

            >

             

             

            <cfdocument format="PDF" overwrite="yes" filename="errordebug.pdf"

            >

             

             

            <cfdump var="#cfcatch#"

            />

             

             

            </cfdocument>

             

             

            </cfcatch>

             

            So my '#cfhttp.news_ID#' is wrong becuase it is NULL. What should I be doing to pass the data from Flex to this CF?

             

            Thanks

            Todd

            • 3. Re: POSTvariable Problem
              crumsberry Level 1

              [Bindable] private var news_ID:int;

              Is this one private because you only use it to check what the variable value is?

               

              I looks liek its getting lost somewhere in here:

              var postVariables:URLVariables = new URLVariables;

              postVariables.news_ID = newsID;

               

              Check it there to see what the value is.

              If it's still 6 there then its in the cf file.

              • 4. Re: POSTvariable Problem
                Toadsteraz Level 1

                Thanks! I figured it out, in my upload.cfm I had to use #FORM.newsID#. Didn't realize the items got passed as FORM object

                 

                Todd