4 Replies Latest reply on Jun 17, 2007 9:13 AM by xrayupload

    Flex3 can not Upload file?!!!!!!!

    xrayupload Level 1
      I use the same code in Flex 2, it works, Then , I move the code to Flex 3, it dosen't. Anybody tell me why? Thanks.

      Flex Code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="vertical" verticalAlign="middle" horizontalAlign="center">

      <mx:Style>
      global {
      fontSize : 12;
      }
      </mx:Style>

      <mx:Script>
      <![CDATA[

      private var file:FileReference = new FileReference();


      [Bindable]
      private var stateText:String = "Please choose a file to upload";


      protected override function createChildren():void {
      super.createChildren();
      file.addEventListener(Event.SELECT, file_select);
      file.addEventListener(Event.COMPLETE, file_complete);
      file.addEventListener(ProgressEvent.PROGRESS, file_progress);
      }


      private function file_select (e:Event):void {
      stateText = "File: " + file.name;
      }


      private function file_complete (e:Event):void {
      stateText = "Upload Complete";
      }

      private function file_progress (e:ProgressEvent):void {
      stateText = Math.round(100 * e.bytesLoaded / e.bytesTotal) + "%";
      }

      private function upload ():void {
      if (file.size > 0) {
      stateText = "Uploading " + file.name;
      var request:URLRequest = new URLRequest(" http://192.168.1.245/upload.aspx");

      file.upload(request,"fileData",true);
      }
      }


      ]]>
      </mx:Script>

      <mx:Panel width="422" height="238" layout="vertical" title="Upload Sample"
      verticalAlign="middle" horizontalAlign="center" >
      <mx:HBox width="346">
      <mx:TextInput text="{stateText}" width="255" editable="false"/>
      <mx:Button label="Browse" click="file.browse();"/>
      </mx:HBox>
      <mx:HBox>
      <mx:Button label="Upload" click="upload();"/>
      </mx:HBox>
      </mx:Panel>
      </mx:Application>



      Upload.aspx Code:

      <script language="C#" runat="server">
      string uploadFolder = "upload";
      private void Page_Load(object sender, System.EventArgs e)
      {
      HttpFileCollection files = Request.Files;

      if (files.Count == 0)
      {
      Response.Write("sorry");
      Response.End();
      }

      string path = Server.MapPath(uploadFolder);


      HttpPostedFile file = files[0];

      if (file != null && file.ContentLength > 0)
      {
      string savePath = path + "/" + Request.Form["fileName"];
      file.SaveAs(savePath);
      }
      }
      </script>