当前位置: 代码迷 >> Android >> Android Base64+Soap+WebService 图片上传内存溢出有关问题
  详细解决方案

Android Base64+Soap+WebService 图片上传内存溢出有关问题

热度:707   发布时间:2016-04-28 07:24:04.0
Android Base64+Soap+WebService 图片上传内存溢出问题

public void testUpload(){  
        try{  
            String srcUrl = "/sdcard/"; //路径  
            String fileName = "aa.jpg";  //文件名  
            FileInputStream fis = new FileInputStream(srcUrl + fileName);  
            ByteArrayOutputStream baos = new ByteArrayOutputStream();  
            byte[] buffer = new byte[1024];  
            int count = 0;  
            while((count = fis.read(buffer)) >= 0){  
                baos.write(buffer, 0, count);  
            }  
            String uploadBuffer = new String(Base64.encode(baos.toByteArray()));  //进行Base64编码  
            String methodName = "uploadImage";  
            connectWebService(methodName,fileName, uploadBuffer);   //调用webservice  
            Log.i("connectWebService", "start");  
            fis.close();  
        }catch(Exception e){  
            e.printStackTrace();  
        }  
    }  
 private boolean connectWebService(String methodName,String fileName, String imageBuffer) {  
        String namespace = "http://134.192.44.105:8080/SSH2/service/IService";  // 命名空间,即服务器端得接口,注:后缀没加 .wsdl,  
                                                                                //服务器端我是用x-fire实现webservice接口的  
        String url = "http://134.192.44.105:8080/SSH2/service/IService";   //对应的url   
        //以下就是 调用过程了,不明白的话 请看相关webservice文档     
        SoapObject soapObject = new SoapObject(namespace, methodName);      
        soapObject.addProperty("filename", fileName);  //参数1   图片名  
        soapObject.addProperty("image", imageBuffer);   //参数2  图片字符串  
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(  
                SoapEnvelope.VER10);  
        envelope.dotNet = false;  
        envelope.setOutputSoapObject(soapObject);  
        HttpTransportSE httpTranstation = new HttpTransportSE(url);  
        try {  
            httpTranstation.call(namespace, envelope); //这一步内存溢出 
            Object result = envelope.getResponse();  
            Log.i("connectWebService", result.toString());  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return false;  
    }  

  相关解决方案