0 Replies Latest reply on May 19, 2011 9:12 PM by ice9_us

    file upload to web server

    ice9_us Level 1

      I need a little help with the file upload process in flex..

       

      I am trying to upload a file.. i had it where i would get a cgi-script url passing as the following

       

      filename="filename"&filedata="data of the file"

       

      then my cgi script "written in C" would read from standard in.. and write the info to a file...

      now i get the following..

       

       

      ------------KM7Ef1gL6Ij5cH2ae0ei4Ij5GI3Ef1
      Content-Disposition: form-data; name="Filename"

      Botanical Garden 239.JPG
      ------------KM7Ef1gL6Ij5cH2ae0ei4Ij5GI3Ef1
      Content-Disposition: form-data; name="Filedata"; filename="Botanical Garden 239.JPG"
      Content-Type: application/octet-stream

       

       

      in the file i am trying to write.... Can anyone help me fix this problem? I am clueless at this point on what to do..

      sample code below is what i got from trying to work this...

      Thanks in advanced for anyones help..

       

      <code>

       

       

       

       

       

      const FILE_UPLOAD_URL:String = "http://172.16.1.6:1111/cgi-bin/login.cgi";

       

       

      private function init():void {

      fileRef =

      new FileReference();

      fileRef.addEventListener(Event.SELECT, fileRef_select);

      fileRef.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);

      fileRef.addEventListener(Event.COMPLETE, fileRef_complete);

      }

       

       

      private function browseAndUpload():void {

      fileRef.browse();

      message.text =

      "";

      }

       

       

      private function fileRef_select(evt:Event):void {

       

      try {

      message.text =

      "size (bytes): " + numberFormatter.format(fileRef.size);

      fileRef.upload(

      new URLRequest(FILE_UPLOAD_URL) );

       

      trace("going to print file data in a sec... ready?");

       

      trace(fileRef.data);

       

      trace(fileRef.name );

      }

      catch (err:Error) {

      message.text =

      "ERROR: zero-byte file";

      }

      }

       

       

      private function fileRef_progress(evt:ProgressEvent):void {

      progressBar.visible =

      true;

      }

       

       

      private function fileRef_complete(evt:Event):void {

      message.text +=

      " (complete)";

      progressBar.visible =

      false;

      }

       

      </code>