5 Replies Latest reply on Jun 1, 2010 10:02 PM by Joe ... Ward

    Uploading Images

    GeorgeWS Level 1

      I have this to read the saved image:

       

      private

       

      function upload():void

      {

       

      var uploader:Uploader = new Uploader();

       

      var dir:File = File.applicationStorageDirectory.resolvePath("images/");

       

      var files:Array = dir.getDirectoryListing();

       

      for (var i:uint = 0; i < files.length; i++)

      {

      file = files[i];

       

       

      if (!file.isDirectory)

      {

      uploader.addFile(file);

      }

      }

      uploader.addEventListener(Event.COMPLETE, uploadCompleteHandler);

      uploader.addEventListener(ProgressEvent.PROGRESS, progressHandler);

      uploader.start(UPLOAD_URL +

      "/upload.cfm");

      }

       

       

      private function progressHandler(event:ProgressEvent):void

      {

       

      trace("Progress", event.bytesLoaded, event.bytesTotal);

      }

       

      /*

      * Upload complete handler.

      */

       

      private function uploadCompleteHandler(event:Event):void

      {

       

      trace("complete");

      }

       

       

      This seems to be doing the right thing. When I use the Debugger it looks like its uploading the image. But It never gets to its destination. I am using ClodFusion 8. I made an errordebug.pdf page to show me whats going on. It says in the detail [empty string] and that my FileField is "File". To me that means I am not calling in the image. I can see that that the images are saved on the local machine. My upload.cfm is like this:

       

      <cffile action="upload" filefield="File" destination="c:\inetpub\wwroot\images\" accept="application/octet-stream"/>

       

       

      Any thoughts would be great for I am stumped.

      Thanks

      George

        • 1. Re: Uploading Images
          Joe ... Ward Level 4

          Without knowing what the Uploader class does, it's hard to know what is wrong. What data type does addFile() take?

          • 2. Re: Uploading Images
            GeorgeWS Level 1

            jpg

            • 3. Re: Uploading Images
              Joe ... Ward Level 4

              Okay, the file format is jpg, but what is the ActionScript data type?

              • 4. Re: Uploading Images
                GeorgeWS Level 1

                I use the web cam on my laptop (but have plans to move this to my new HTC Incredable) I got this to work befor but just cannot seem to remember what I did to get it going. But this is what I do with the captured image:

                 

                private

                 

                 

                 

                 

                 

                function getJPEG(bmd:BitmapData):ByteArray {

                 

                var jpg:JPGEncoder = new JPGEncoder();

                 

                return jpg.encode(bmd);

                }

                 

                 

                So I see the images in the applicationStorageDirectory location then upload button pressed and this gets run:

                 

                private

                 

                 

                function upload():

                void

                {

                 

                var uploader:Uploader = new Uploader();

                 

                var dir:File = File.applicationStorageDirectory.resolvePath("images/");

                 

                var files:Array = dir.getDirectoryListing();

                 

                for (var i:uint = 0; i < files.length; i++)

                {

                file = files[i];

                 

                 

                if (!file.isDirectory)

                {

                uploader.addFile(file);

                }

                }

                uploader.addEventListener(Event.COMPLETE, uploadCompleteHandler);

                uploader.addEventListener(ProgressEvent.PROGRESS, progressHandler);

                uploader.start(UPLOAD_URL +

                "/upload.cfm");

                }

                 

                 

                 

                I can get a test response from my upload.cfm I  know the above hits the cfm file. When I look at my ColdFusion error its telling me that Im not sending a file. I keep thinking its the filefield name.

                 

                <cffile action="upload"
                         filefield="file"
                         destination="c:\inetpub\wwwroot\Files\Displays\"
                         nameconflict="overwrite"
                         accept="application/octet-stream"/>

                 

                Thanks for looking

                • 5. Re: Uploading Images
                  Joe ... Ward Level 4

                  A File object doesn't represent the data in the file. Probably you need to read the file into a ByteArray using the FileStream class and pass that ByteArray to the Upload.addFile() method.