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

greenredshark 2012-06-07 11:15:32

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;
}

...全文
766 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzoy 2014-04-02
  • 打赏
  • 举报
回复
看来这是一个普遍的问题,也没人提怎么解决的,我的也是,现在弄的图片的分辨率特别小才能成功
小胡子_01 2013-11-25
  • 打赏
  • 举报
回复
同样遇到这样的问题,求解决方案
rui90102 2013-11-08
  • 打赏
  • 举报
回复
楼主,最后怎么解决的呀,我也碰到这个问题了
h309849232 2012-06-29
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
分块啊 没什么好办法
做个分块私有协议
[/Quote]

分块怎么做啊。。。?
greenredshark 2012-06-07
  • 打赏
  • 举报
回复
是吗?通用做法?

我之前也见到有人提分块

那么其他上传图片的方法也要分块吗
比如说Http
qdkfriend 2012-06-07
  • 打赏
  • 举报
回复
分块啊 没什么好办法
做个分块私有协议
greenredshark 2012-06-07
  • 打赏
  • 举报
回复
小的图片没问题

但是一发送2M左右的正式图片就报内存溢出。。。

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧