android base64.encodeToString string to asp.net webservice

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

May 12, 2017 8:21:24 PM via Website

Dear team,
i am new android development. i try to upload a image from android app and upload using asp.net webservice and insert into sql.

android code

 Uri selectedImageUri = data.getData();
           File x  =new File(getRealPathFromURI(selectedImageUri));
           Bitmap myBitmap = BitmapFactory.decodeFile(x.getAbsolutePath());
           byte[] byt=getBytesFromBitmap(myBitmap);
           Log.e("byt string",""+byt.toString());
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
           myBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
           byte[] byte_arr  = baos.toByteArray();
           imgview.setImageBitmap(myBitmap);
           String strBase64 = Base64.encodeToString(byte_arr,Base64.DEFAULT);
           Log.e("strBase64 ",strBase64);

strBase64 string value is

iVBORw0KGgoAAAANSUhEUgAAAeAAAAExCAIAAAAr1OZIAAAAA3NCSVQICAjb4U/gAAAgAElEQVR4
nLS9W69k2XEm9kXE2jvzXOpe1Xf2nd2t7mazeREpiaKGkiBxxjAEmwPDD5bnwTAgA4YA+Zf41YYN
w/Ni+DaABxoLkDyixOaQHFG8i2yS1dfq6kt1V3XdzqlzTu69Ij4/xNo781TTsuSx8qH71DmZO3eu
FSviiy++iJSfff9HAEgHICIASAIAlKSIRAQQJAkHEA4AEZHPyZeICBAiIkoAKoWkqgJw5NUAAOIA
jD3J3eokFUZShABGguRIRgQNALreVFWsK6UsoKUUlM7MipqqSgkRCelIemFEKIQkJSJCYe5OUZIK
zg9IRAShJPOWIyqAfFV+XhEjKfmpQyICuv49OAIIEkAERMRMACAMgBgioq1PEECAJIX5P9RaVQGg
owAwKSQNMo6jIJ8TtVaGkaysJKWCpLu7OwB3d9a8n4gIH0nG0VGt1dt7FZK1DrXWGiNJWFHVra4A
EO1VFRzNbLl1Ynt7++Tuzs7Oztb26VKKOAGI2bw7lBARdSEZKiRNERGQLiIGBMkoGhFmnYjAoKpK
FZFSFIBqSSMhSXqu8ziOgEbEOI4RQ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CtPGTKVjaDXiJAgANGMqyEiAyKT2XTKtdbBB3eXilrrKmqt
VZ3jOCbvHG1TPWM2SVYnacKu60RUVfu+V1VTAPDQcRxVZdo4TABTZpQ9Y8mIKNrp9JAQM8sjkeRG
plgCIZmhXTdAX9vfiZNNO4mpnJDvu8m7MWEVGREimngnImRyfJjqGe2eQQC

my asp.net code
here i will pass the above value to the str_image string

str_image = str_image + "=="; 
    byte[] imageBytes = Convert.FromBase64String(str_image);
    System.Drawing.Image img = null;
    byte[] photo_aray = null;
     try
    {
         using (System.IO.MemoryStream ms1 = new System.IO.MemoryStream(imageBytes))
        {
            img = System.Drawing.Image.FromStream(ms1);
            if (img != null)
            {
                photo_aray = new byte[ms1.Length];
                ms1.Position = 0;
                ms1.Read(photo_aray, 0, photo_aray.Length);img.Save(@"D:\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                Response.Write("Finished");
            }
        }
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message.ToString()); 
    }