0 Replies Latest reply on May 28, 2010 1:19 PM by GeorgeWS

    Uploading

    GeorgeWS Level 1

      I have this:

       

      <mx:Script>

      <![CDATA[

       

       

      import flash.net.navigateToURL;

       

      import com.adobe.images.JPGEncoder; // JPGEncoder class from the ActionScript 3.0 corelib project

       

       

      import com.adobe.net.Uploader; // Class used to upload files to a URL

       

       

      import flash.filesystem.*;

       

      import flash.events.*;

       

      private var file:File; // Used for referencing stored image files

       

       

      private var stream:FileStream; // Used for writing JPEG data to an image file

       

       

      private var bmd:BitmapData; // Used to store pixels from the Video object

       

       

      private var camera:Camera; // Used to referemce a camera

       

       

      private const UPLOAD_URL:String = "http://www.mysite.com/programs/ymcochains/ymcochains/bin-debug";

       

       

      /*

      * Initialization. Checks to see if there is an active camera.

      */

       

       

      private function init():void

      {

       

      if (Camera.getCamera())

      {

      setCamera();

      }

       

      else

      {

       

       

      trace("No cameras are available.");

      }

      }

       

      /*

      * Sets the camera object to reference the default camera. Then

      * uses that camera for the video object's image.

      */

       

       

      private function setCamera():void

      {

      camera = Camera.getCamera();

      video.attachCamera(camera);

      camera.addEventListener(ActivityEvent.ACTIVITY, setSize);

      }

       

       

      /*

      * Sets the size of the video object, based on the size of the camera.

      */

       

       

      private function setSize(...args):void

      {

      camera.removeEventListener(ActivityEvent.ACTIVITY, setSize);

      video.width = camera.width;

      video.height = camera.height;

       

      }

       

      /*

      * Saves the current image in the video object to the preview (bmp) bitmap.

      */

       

       

      private function shoot():void

      {

      flasher();

      saveBtn.enabled =

      true;

      bmd =

      new BitmapData(video.width, video.height);

      bmd.draw(video);

       

      var bmp:Bitmap = new Bitmap(bmd);

      bmp.x = (stage.stageWidth - bmp.width)/2

      shot.source = bmp;

      }

       

      /*

      * Emulates a camera flash effect by filling the screen with white

      * by quickly displaying a full-screen NativeWindow object.

      */

       

       

      private function flasher():void

      {

       

      var windowInitOpts:NativeWindowInitOptions = new NativeWindowInitOptions();

      windowInitOpts.systemChrome = NativeWindowSystemChrome.NONE;

      windowInitOpts.type = NativeWindowType.LIGHTWEIGHT;

       

      var flashCube:NativeWindow = new NativeWindow(windowInitOpts);

      flashCube.x = 0;

      flashCube.y = 0;

      flashCube.width = Capabilities.screenResolutionX;

      flashCube.height = Capabilities.screenResolutionY;

      flashCube.visible =

      true;

      setTimeout(closeFlash, 100, flashCube);

      }

       

      /*

      * Closes the camera flash NativeWindow.

      */

       

       

      private function closeFlash(flashCube:NativeWindow):void {

      flashCube.close()

      }

       

      /*

      * Called when the user clicks the Save button. This method saves the current

      * preview image to a file in the images subdirectory of the application storage directory

      */

       

       

      private function save():void {

      file = File.applicationStorageDirectory;

      file = file.resolvePath(

      "images/" + new Date().time.toString() + ".jpg");

       

      trace(file.nativePath);

      stream =

      new FileStream;

      stream.open(file, FileMode.WRITE);

       

      var data:ByteArray = getJPEG(bmd);

      stream.writeBytes(data, 0, data.length);

      stream.close();

      }

       

      /*

      * Converts a BitmapData object into JPEG data.

      */

       

       

      private function getJPEG(bmd:BitmapData):ByteArray {

       

      var jpg:JPGEncoder = new JPGEncoder();

       

      return jpg.encode(bmd);

      }

       

      /*

      * Called when the user clicks the Upload button. Creates an array of the saved files,

      * creates an Uploader object, adds the files to the Uploader object's file list, and then

      * starts the upload.

      */

       

       

      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");

      }

       

      /*

      * Upload progress handler.

      */

       

       

       

      private function progressHandler(event:ProgressEvent):void

      {

       

       

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

      }

       

      /*

      * Upload complete handler.

      */

       

       

      private function uploadCompleteHandler(event:Event):void

      {

       

       

      trace("complete");

      }

       

      /*

      * Called when the user clicks the 'View in browser' button.

      * Displays the web directory containing the uploaded images

      * in the default system web browser.

      */

       

       

      private function viewHTML():void

      {

       

       

      var urlReq:URLRequest = new URLRequest(UPLOAD_URL + "/uploaded");

      navigateToURL(urlReq);

      }

      ]]>

       

      </mx:Script>

       

       

       

      Every part works except the upload I get an error:

      Error #2044: Unhandled ioError:. text=Error #2038: File I/O Error. URL: http://www.mysite.comt/programs/ymcochains/ymcochains/bin-debug/upload.cfm

       

      The upload.cfm is like this:

       

      <cflile action="upload" filefield="filedate" destoination="c://inetpub/wwwroot/mysite/files/" namecoflict="overwrite" accept="application/octet-stream"/>

       

      I think its a path issue but am baffled. I see lots of posts but no go..

       

      Any thoughts would be great

       

      Im using Air 1.5 and CF 8 I have done this before just forgot what I did to ovecome this error.

       

      George