0 Replies Latest reply on Jun 6, 2009 11:17 AM by armando.manden

    Uploading files to remote server

    armando.manden

      hi all,

      i want to send a file to server (from my hard disk) but i can´t do that.

      i was trying this:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:net="flash.net.*" creationComplete="init()">
          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;

                  [Bindable]
                  private var fileRef:FileReference;
                  [Bindable]
                  private var fileSelected:Boolean = false;
                  [Bindable]
                  private var status:String = "Select file";

                  private function init():void
                  {
                      fileRef = new FileReference();
                      fileRef.addEventListener(Event.SELECT, onFileSelected);
                      fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadComplete);
                      fileRef.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
                      fileRef.addEventListener(IOErrorEvent.IO_ERROR, onUploadError);
                      fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadError);
                  }


                  /**
                   * Called by the button, calls file browser window.
                   */
                  private function selectFile(event:MouseEvent):void
                  {
                      fileRef.browse();
                  }

                  /**
                   * Called by the button, starts the upload.
                   */
                  private function uploadFile(event:MouseEvent):void
                  {
                      if (!fileSelected || (urlInput.text.length == 0)) {
                      Alert.show("Insert a URL and select a file.");
                      return;
                  }

                  fileRef.upload(new URLRequest(urlInput.text));
                  }

                  /**
                   * Called when a file is selected in the file chooser window.
                   */
                  private function onFileSelected(event:Event):void
                  {
                      fileSelected = true;
                      fileInput.text = fileRef.name;
                      status = "Ready";
                  }

                  /**
                   * Called on upload complete.
                   */
                  private function onUploadComplete(event:DataEvent):void
                  {
                      status = "Complete";
                  }

                  /**
                   * Upload progress.
                   */
                  private function onUploadProgress(event:ProgressEvent):void
                  {
                      status = ((event.bytesLoaded * 100) / event.bytesTotal).toString();
                  }

                  /**
                   * Upload error.
                   */
                  private function onUploadError(event:Event):void
                  {
                      if (event is IOErrorEvent)
                      Alert.show((event as IOErrorEvent).text.toString());
                      else if (event is SecurityErrorEvent)
                      Alert.show((event as SecurityErrorEvent).text.toString());
                  }
              ]]>
          </mx:Script>

          <mx:Form x="423.5" y="204">
              <mx:FormItem label="Remote URL">
                  <mx:TextInput id="urlInput" width="200" />
              </mx:FormItem>
              <mx:FormItem label="File name">
                  <mx:TextInput id="fileInput" editable="false" width="200" />
              </mx:FormItem>
              <mx:FormItem label="Status">
                  <mx:Text text="{status}" />
              </mx:FormItem>

              <mx:ControlBar>
                  <mx:Button id="selectBut" label="Select file" click="selectFile(event)" />
                  <mx:Button id="uploadBut" label="Upload file" click="uploadFile(event)" enabled="{fileSelected}" />
              </mx:ControlBar>

          </mx:Form>

       

      </mx:Application>

      when i look into the my remote folder the file isn´t.

      i don´t know what´s wrong.

      thanks.