3 Replies Latest reply on May 26, 2013 8:58 AM by archemedia

    Upload bytearray problem

    archemedia Level 4



      I hope someone can help me after hours of forum reading and struggling...


      I have a byte array resulting from an microphone recording in a flex mobile project.

      I want to save this as a .wav file on the server.

      I have to use UrlLoader since I don't have a file reference


      this is my code:


      private function uploadAudio(data:ByteArray):void


                                              var urlVariables:URLVariables = new URLVariables();

                                              urlVariables.filename = "myFile.wav";

                                              urlVariables.file = data;


        var url:String = "http://myDomain/audioUploader.php";    

                                              var urlRequest:URLRequest = new URLRequest(url);   

                                              urlRequest.method = URLRequestMethod.POST;  

                                              urlRequest.data = urlVariables;


                                              urlLoader = new URLLoader();  

        //urlLoader.dataFormat = URLLoaderDataFormat.BINARY;

                                              urlLoader.addEventListener(Event.COMPLETE, completeHandler);






      Watching Charles to monitor server traffic, I can see that urlVariables.file is empty even before going to the server. In debugging mode however, urlVariables.file holds the byteArray.


      Any idea what I'm doing wrong here?





        • 1. Re: Upload bytearray problem
          archemedia Level 4



          I changed my code from:


          urlVariables.filename = "myFile.wav";

          urlVariables.file = data;

          urlRequest.data = urlVariables;




          urlRequest.data = data; (the byteArray)


          now it passes to the server.

          But how do I retreive it on the server?



          • 2. Re: Upload bytearray problem
            saisri2k2 Level 4

            Have you tested with the filereference? May you can try with the data property of it, and on he server you can get it as a stream. Dunno howiit works with php

            • 3. Re: Upload bytearray problem
              archemedia Level 4

              fileReference is not an option becaus you have to browse first. I can't do that.

              Found the solution though:


              var urlVariables:URLVariables = new URLVariables();

                                                      urlVariables.filename = "myFileName";


                                                      var loader:URLLoader = new URLLoader();

                                                      loader.dataFormat= URLLoaderDataFormat.BINARY;


                                                      var wrapper:URLRequestWrapper = new URLRequestWrapper(data, "myFileName", null, urlVariables);

                                                      wrapper.url = "http://myDomain.com/uploader.php";


                                                      loader.addEventListener( Event.COMPLETE, completeHandler );



              The URLRequestWrapper class does it!


              * @author Jonathan Marston