2 Replies Latest reply on Jan 22, 2009 9:42 PM by SNTS.Santosh

    Save image (JPEG) from Base64

    SNTS.Santosh
      Hi All,

      I am developing an AIR Application. I have to download image from server to local system. For this I am trying to write a image(jpg format) at local root path from base64 string. I am getting this base64 string data from web service.
      I have to do voice-versa also for upload image, For upload image I have to convert image from local path to base64 String

      Please help me.

      Thanks.
        • 1. Re: Save image (JPEG) from Base64
          Joe ... Ward Level 4
          Flex has the mx.utils.Base64Decoder and mx.utils.Base64Encoder classes for working with Base64. Use the AIR File class for reading and writing local files.
          • 2. Re: Save image (JPEG) from Base64
            SNTS.Santosh Level 1
            Hi Joe,
            Thanks for your reply.
            With this i am able to write a file on local path but I am not able to read image file in Base64String.
            this is my code, please help me.
            I have to also read a .ZIP file flex.

            // ---------------------------------------------------------------------------
            var file:File = File.documentsDirectory.resolvePath("c:/image_0.jpg");
            var base64Str:String="";
            var params:Object = new Object();
            var encoder : Base64Encoder = new Base64Encoder();
            var stream:FileStream = new FileStream();
            stream.open(file,FileMode.READ);
            stream.readByte();
            //stream.readMultiByte(stream.bytesAvailable,base64Str);
            //encoder.encodeBytes(stream.readByte(),0,stream.bytesAvailable);
            //encoder.encode(stream.readByte());
            stream.close();
            flash.system.System.gc();
            base64Str = encoder.flush();
            trace(base64Str);