Skip to main content
Participant
August 13, 2010
Answered

Automatically accept file upload

  • August 13, 2010
  • 1 reply
  • 801 views

I'm working on a Flex (Actually AIR) app.  I have functionality where files are stored in a folder in the application directory by the user in the field.  When that user gets back to the office they connect to the network.  At that point the AIR app senses it has access to the web application.  At this point I want all the files stored in the folder to automatically be uploaded to the CF server.  I have the AIR code done - but I cannot seem to figure out how to get CF to accept the files without forcing the user to log into a CF application, browse to them, and upload.

Anyone done this sort of thing?  This should be simple.

Thanks!

This topic has been closed for replies.
Correct answer JR__Bob__Dobbs

The forum's XML formatting seems to be removing some of the quotes from the MXML.  Here is the MXML sample again.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="application_creationComplete()">

    <mx:Script>
        <![CDATA[
            import flash.net.*;
            import mx.controls.Alert;

            private var fileRef:FileReference = new FileReference();
           
           
            private function application_creationComplete():void
            {
                //setup fileRef object events
                this.fileRef.addEventListener(Event.SELECT, fileRef_SelectHandler);
                this.fileRef.addEventListener(Event.COMPLETE, fileRef_Complete);
            }
           
            //select event handler for fileRef object
            private function fileRef_SelectHandler(e:Event):void
            {
                try
                {
                    var req:URLRequest=new URLRequest();
                    req.url="http://localhost/file_upload.cfm";
                    req.method="POST";
                    req.contentType="multipart/form-data";
                    this.fileRef.upload(req, "filedata");
                }   
                catch(e:Error)
                {
                    Alert("Unable to upload\n" + e.toString());
                }
            }
           
            //complete handler for fileRef object
            private function fileRef_Complete(e:Event):void
            {
                Alert.show("Complete");
            }
           
            //browse button click event handler
            private function browseBtn_click(e:MouseEvent):void
            {
                //allow user to browse for files   
                this.fileRef.browse();           
            }
           
        ]]>
    </mx:Script>
   
    <mx:Button id="browseBtn" label="Browse" click="browseBtn_click(event)" />
   
</mx:Application>

1 reply

Inspiring
August 13, 2010

Here is some Flex 3 and CF proof of theory code.   This sample does not use any sort of authentication.

Flex 3 MXML:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="application_creationComplete()">

     <mx:Script>
          <![CDATA[
               import flash.net.*;
               import mx.controls.Alert;

               private var fileRef:FileReference = new FileReference();
               
               
               private function application_creationComplete():void
               {
                    //setup fileRef object events
                    this.fileRef.addEventListener(Event.SELECT, fileRef_SelectHandler);
                    this.fileRef.addEventListener(Event.COMPLETE, fileRef_Complete);
               }
               
               //select event handler for fileRef object
               private function fileRef_SelectHandler(e:Event):void
               {
                    try
                    {
                         var req:URLRequest=new URLRequest();
                         req.url="http://localhost/file_upload.cfm";
                         req.method="POST";
                         req.contentType="multipart/form-data";
                         this.fileRef.upload(req, "filedata");
                    }     
                    catch(e:Error)
                    {
                         Alert("Unable to upload\n" + e.toString());
                    }
               }
               
               //complete handler for fileRef object
               private function fileRef_Complete(e:Event):void
               {
                    Alert.show("Complete");
               }
               
               //browse button click event handler
               private function browseBtn_click(e:MouseEvent):void
               {
                    //allow user to browse for files     
                    this.fileRef.browse();               
               }
               
          ]]>
     </mx:Script>
     
     <mx:Button id="browseBtn" label="Browse" click="browseBtn_click(event)" />
     
</mx:Application>

CFML: Note that Flex file uploads use mime type of application/octet-stream regardless of file's mime type.


<cffile action="upload" filefield="filedata" destination="C:\docstore" nameconflict="makeunique" accept="application/octet-stream" />

JR__Bob__DobbsCorrect answer
Inspiring
August 13, 2010

The forum's XML formatting seems to be removing some of the quotes from the MXML.  Here is the MXML sample again.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="application_creationComplete()">

    <mx:Script>
        <![CDATA[
            import flash.net.*;
            import mx.controls.Alert;

            private var fileRef:FileReference = new FileReference();
           
           
            private function application_creationComplete():void
            {
                //setup fileRef object events
                this.fileRef.addEventListener(Event.SELECT, fileRef_SelectHandler);
                this.fileRef.addEventListener(Event.COMPLETE, fileRef_Complete);
            }
           
            //select event handler for fileRef object
            private function fileRef_SelectHandler(e:Event):void
            {
                try
                {
                    var req:URLRequest=new URLRequest();
                    req.url="http://localhost/file_upload.cfm";
                    req.method="POST";
                    req.contentType="multipart/form-data";
                    this.fileRef.upload(req, "filedata");
                }   
                catch(e:Error)
                {
                    Alert("Unable to upload\n" + e.toString());
                }
            }
           
            //complete handler for fileRef object
            private function fileRef_Complete(e:Event):void
            {
                Alert.show("Complete");
            }
           
            //browse button click event handler
            private function browseBtn_click(e:MouseEvent):void
            {
                //allow user to browse for files   
                this.fileRef.browse();           
            }
           
        ]]>
    </mx:Script>
   
    <mx:Button id="browseBtn" label="Browse" click="browseBtn_click(event)" />
   
</mx:Application>

Participant
August 13, 2010

Super!

Thanks Bob!