1 Reply Latest reply on Oct 14, 2009 8:13 PM by Subeesh Arakkan

    Problem displaying an image - Pls help

    kgladwin

      I have a java servlet which reads an image as a byte array. I need to display the image on my flex window.

      I use httpservice to call the doGet method of my servlet. This returns me a byte array. But when I set that to my flex image it does not display.

      Any suggestions??

       

      Java Code

      ---------------

      byte[] imageByte = null;

      imageByte = (byte[])httpSession.getAttribute("imgData");

      PrintWriter out = response.getWriter();
      out.println((Object)imageByte);

       

      Flex Code

      ---------------

      var httpService:HTTPService = new HTTPService();
      httpService.url = "http://localhost:8080/gss/UploadHandler";
      httpService.method = "GET";
      httpService.resultFormat = "object";
      httpService.addEventListener(ResultEvent.RESULT, resultHandler);
      httpService.addEventListener(FaultEvent.FAULT, faultHandler);
      httpService.send();             

       

      private function resultHandler(event:ResultEvent):void {

            var imgStream:ByteArray = new ByteArray();
            imgStream = event.result as ByteArray;
            imgPhoto.source = imgStream;
      }