0 Replies Latest reply on May 6, 2014 12:47 AM by poortip87

    How to upload file to server?

    poortip87 Level 1

      Hi all,

       

      I am writing a code to upload a zip file to client server. I am using Flash Builder 4.6, Extension Builder 2.1 on a Win 7 machine. My request includes login and password authentication and other params. I am sending the file contents as byte array. But, the return code I get from the server suggests that it does not receive any file. It gets null in the file parameter.

       

      Here is my code,

       

      var request:URLRequest = new URLRequest("http://<url>api/plugin.php/");

      request.method = URLRequestMethod.POST;

       

      var fileStream:FileStream = new FileStream();

      fileStream.open(PKG_FILE, FileMode.READ);

       

      var byteArr:ByteArray = new ByteArray();

      fileStream.readBytes(byteArr, 0, fileStream.bytesAvailable);

       

      request.data = "login=" +

        LOGIN +

        "&password=" +

        MD5.hash(PASSWORD) +

        "&pkg=" +

        byteArr +

        "&pkg_name=" +

        PKG_NAME;

       

      var loader:URLLoader = new URLLoader();

       

      // Call OnSuccessfulExportif export completes

      loader.addEventListener(Event.COMPLETE, OnSuccessfulExport);

       

      // Call OnUnsuccessfulExportif export failed

      loader.addEventListener(IOErrorEvent.IO_ERROR, OnUnsuccessfulExport);

      loader.load(request);

       

      ======================================================

      private function OnSuccessfulExport(event:Event):void

      {

        trace(event);

      }

       

      I get a callback on OnSuccessfulExport function, but the value returned from the server in event.target.data is that the server received no file.

       

      Am I missing something here?