4 Replies Latest reply on Jun 24, 2010 6:04 AM by Pranke1

    Async reading a file and sending it via JSON to a WebService

    Pranke1

      Hi guys,

       

      I need to read a file from the HDD and send it to a WebService via JSON. This does work for me, but is extremly slow. The program seems to hang while reading the file. I am writing the bytes to an ByteArray and in a for-loop I am writing each byte to an array, which is then send via JSON. Here is some of my code:

       

      this.readFile = function(inputfile){

        var file = new air.File(inputfile);

        var bytes = new air.ByteArray();

        var byteArr = [];

       

        if (file.exists) {

          var stream = new air.FileStream();

          stream.open(file, air.FileMode.READ);

          stream.readBytes(bytes, 0, file.size);

          stream.close();

        }

        for(var i=0;i<bytes.length;i++){

          byteArr[i] = bytes[i];

        }

       

        return byteArr;

      };

       

      My questions are: Is there a way to read the Bytes async and is it possible to write the bytes directly into an array and not into an ByteArray? (Or is it possible to convert the ByteArray in a fast way?)

       

      Thanks for any help