自己写就比较麻烦了,还是用apache的multipart的库,方便点儿
解决方案 »
- 关于android中XML解析的问题
- 有android开发google map的兄弟吗?道路偏移怎么解决啊?
- 输入法问题!EditText的属性InputMethod等问题
- 调用android手机自带相机出问题
- 如何能显示多个自定义的view类
- 躲开危险的洗虾粉,全面的健康饮食-饮食禁忌--Android应用!
- 在安卓下用c语言,来执行adb shell,生成so文件释放接口给上层
- Android数据缓存
- 请教在Viewpager中获取所有fragment中的数据的问题
- Android Studio如何配置环境变量
- 手机屏幕适配遇到虚拟键的问题
- AsyncHttpClient RequestParams怎么封装下面格式的json
MultipartEntity mpEntity = new MultipartEntity(); //文件传输
ContentBody cbFile = new FileBody(new File(listd.get(0).toString()));
mpEntity.addPart("pic[]", cbFile); // <input type="file" name="userfile" /> 对应的
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());//通信Ok
请问多文件怎么改啊,我现在手写.get(0)
怎么写这个循环,请指教
有几个文件就加几个呗
for(int i=0;i<listd.size();i++)
{
File file = new File(listd.get(i).toString());
MultipartEntity mpEntity = new MultipartEntity(); //文件传输
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("pic[]", cbFile); // <input type="file" name="userfile" /> 对应的
Log.i("post", cbFile.toString());
}
httppost.setEntity(mpEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());//通信Ok
String json="";
String path="";
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity,"utf-8"));
json=EntityUtils.toString(resEntity,"utf-8");
JSONObject p=null;
try{
p=new JSONObject(json);
path=(String) p.get("path");
}catch(Exception e){
e.printStackTrace();
}
}
if (resEntity != null) {
resEntity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
return path;
}
{
File file = new File(listd.get(i).toString());
MultipartEntity mpEntity = new MultipartEntity(); //文件传输
ContentBody cbFile = new FileBody(file);
mpEntity.addPart("pic[]", cbFile); // <input type="file" name="userfile" /> 对应的
Log.i("post", cbFile.toString());
}
httppost.setEntity(mpEntity);MultipartEntity 只需要一个,你放到 for 循环里面干啥。
而且,如果mpEntity是在for里面new出来的,你在for外面httppost.setEntity(mpEntity);根本编译不过。估计是你在之前的哪个位置又new了一个
大哥,我这说的是多图,不是文字+图
我的也是需要上传多图但是还需要上传文字,就是文字和多图同步上传啊!你的解决了告诉我一下!原理都是一样的啊!
呵呵,我也一样,我在也是多图加文字,昨天多图解决了,文字没解决,今天换了方法,图也没解决了嗯嗯!我也是啊!就是我的后台是用PHP啊!我只把单图片上传解决了啊!但是现在多图和文字同步上传到服务器还没有解决啊!这个问题都困扰我好久了啊!