1. Download our Official Android App: Forums for Android!

Apps Unable to upload picture when sending as Base64 String

Discussion in 'Android Development' started by Mamatha Kota, Jan 8, 2014.

  1. Mamatha Kota

    Mamatha Kota Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jan 8, 2014

    Jan 8, 2014
    1
    0
    5
    I am trying to send an image to our asp.net webservice from android.Here is my sample code :

    [HIGH]// Getting image from Gallery

    Uri selectedImage = data.getData();
    String[] filePathColumn = { MediaStore.Images.Media.DATA };

    Cursor cursor = getContentResolver().query(selectedImage,
    filePathColumn, null, null, null);
    cursor.moveToFirst();

    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    picturePath = cursor.getString(columnIndex);

    cursor.close();

    /* BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;*/

    thumbnail = (BitmapFactory.decodeFile(picturePath));
    img_photo.setImageBitmap(thumbnail);

    // converting imag into base64 string

    img_photo.buildDrawingCache();
    Bitmap bm = img_photo.getDrawingCache();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos); // bm is the bitmap

    byte[] photo = baos.toByteArray();
    System.out.println("this is byte array" + bytearray);

    String temp_base =Base64.encodeToString(photo,Base64.NO_WRAP);
    // calling webservice

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    request.addProperty("CarID", SellCarDetailView.sellcardetails_carid);
    request.addProperty("pic",temp_base);
    System.out.println("this is piccontent" +temp_base);
    try {

    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);
    soapEnvelope.encodingStyle = SoapEnvelope.ENC;
    // new MarshalBase64().register(soapEnvelope);
    soapEnvelope.dotNet = true;
    soapEnvelope.setOutputSoapObject(request);
    HttpTransportSE aht = new HttpTransportSE(URL);
    //AndroidHttpTransport aht = new AndroidHttpTransport(URL);
    aht.call(SOAP_ACTION, soapEnvelope);

    // SoapObject response = (SoapObject)envelope.getResponse();
    SoapPrimitive response = (SoapPrimitive) soapEnvelope.getResponse();
    String temp3 = response.toString();

    Log.v("TAG", temp3);

    } catch (Exception e) {
    e.printStackTrace();
    }[/HIGH]


    How ever i am getting "invalid parameter" at web service end.
    [HIGH]// Asp.net code

    [ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Xml)]
    [WebMethod(EnableSession = true)]
    public string UploadPictureByCarIDFromAndroid(string CarID, string make, string model, string year, string UserID, string pic, string AuthenticationID, string CustomerID, string SessionID)
    {

    string bStatus = "Failed";
    MobileBL objMobile = new MobileBL();
    UsedCarsInfo objCarPicInfo = new UsedCarsInfo();

    try
    {
    try
    {
    if (AuthenticationID == ConfigurationManager.AppSettings["AppleID"].ToString())
    {
    objCarPicInfo.Carid = Convert.ToInt32(CarID);
    byte[] picContent = Convert.FromBase64String(pic);
    // byte[] picContent = Base64.decode(pic);
    MemoryStream ms = new MemoryStream(picContent, 0,picContent.Length); // getting "invalid length"
    ms.Write(picContent, 0, picContent.Length);
    Bitmap oBitmap1 = new Bitmap(ms);// getting "invalid length" error here
    // System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);




    }
    }
    catch (Exception ex)
    {

    }

    }
    catch (Exception ex)
    {
    }


    return bStatus;
    }[/HIGH]


    I am getting "invalid length" error when sending the image.Any help is highly appreciated.
     

    Advertisement

Share This Page

Loading...