locked
how to receive the byteArray image and save the image to server? RRS feed

  • Question

  • Hi, all.  I stucked by the question how to receive the image passed from Flex HTTPService, and how to save the image received from client side to server. (I don't have a real server, I am using virtual directory as a server. that means I only need to save the image to any folder in the virtual directory). I have tried to find way to save the image to server, but the server side code seems not working. can any IT PRO help me out ? Thanks a lot. 
    my code is below:


    client side code: //I think for client side code should be fine, there is not error

    private function browseImageClicked():void
     {
     var f:FileFilter = new FileFilter("PNG","*.png");
          fileReference.browse([f]);
          fileReference.addEventListener(Event.SELECT,onFileSelect);
          fileReference.addEventListener(Event.COMPLETE,onFileComplete);
     }
     private function onFileSelect(event:Event):void
     {
      fileReference.load();
     }
     private function onFileComplete(event:Event):void
     {
     var byArray:ByteArray = fileReference.data;
          var image:Image = new Image();
          image.source=byArray;
          var bmpData:BitmapData;
          bmpData = new BitmapData(48, 48, true, 0x00ffffff);
                    bmpData.draw(image);
           var imageData:ByteArray = sdf.encode(bmpData);
          
            var encoder : Base64Encoder = new Base64Encoder();
                   encoder.encodeBytes(imageData);
                      var params:Object = { image_data: encoder.flush() };
                     imageSend.send(params);
     }
     

    server side code: // cannot work, I cannot get the image byte array. seems not working. I don't know how to get  the byteArray from client side, and how to save it to virtual directory.
     
       Dim byteArray As Byte()
            Dim stream As System.IO.MemoryStream
            Dim img As Image
            stream = New System.IO.MemoryStream(bytearray)
            img = Image.FromStream(stream)
            img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    Thursday, July 30, 2009 3:39 AM