开发者

Uploading image to the server

开发者 https://www.devze.com 2023-02-17 15:41 出处:网络
As part of my project I need to upload an image to the server. In the server part I have a web service that will accept byte array and converting in to image. In my client part(Android + ksoap2) I con

As part of my project I need to upload an image to the server. In the server part I have a web service that will accept byte array and converting in to image. In my client part(Android + ksoap2) I converted the image to byte[] array using Base64 encoding. But I could not pass the byte ar开发者_JS百科ray to the web service. It is showing some serialization problem. How can I pass the byte array to the web service using ksoap2.Somebody please help me.....


Try with this code

Serialize byte array using MarshalBase64

    MarshalBase64 marshal = new MarshalBase64();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    bmp.compress(CompressFormat.PNG, 100, out);
    byte[] raw = out.toByteArray();

    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
        OPERATION_NAME);
    request.addProperty("image", raw);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    marshal.register(envelope);
    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);

    try

    {

        httpTransport.call(SOAP_ACTION, envelope);
        Object response = envelope.getResponse();
        }

    catch (Exception exception)

    {
        exception.printStackTrace();

    }

}

Refer Serialize byte array using ksoap android

0

精彩评论

暂无评论...
验证码 换一张
取 消