RequestParams params = new RequestParams();
params.add("ordernum",ordernum);
params.add("username",username);
for(int i=0; i<filesList.size();i++){
try {
params.put("images[" + i + "]",filesList.get(i),"application/octet-stream");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Log.i(MyConfig.TagPic,"打印准备上传的图片资料流:"+filesList.get(i).getPath());
}
MyBaseClient.post(MyConfig.urlDataUpload,params,new AsyncHttpResponseHandler(){
@Override
public void onStart() {
super.onStart();
} @Override
public void onProgress(int bytesWritten, int totalSize) {
super.onProgress(bytesWritten, totalSize);
int count = (int) ((bytesWritten * 1.0 / totalSize) * 100);
// 上传进度显示
progressBar.setProgress(count);
tv_progress.setText("正在上传资料....."+count+"%");
Log.i("上传 Progress>>>>>", "count="+count+"--"+bytesWritten + " / " + totalSize);
} @Override
public void onSuccess(int statusCode, String content) {
super.onSuccess(statusCode, content);
Log.i("main","成功了");
mDialog.dismiss(); } @Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
super.onFailure(statusCode, headers, responseBody, error);
mDialog.dismiss();
}
});

最近使用asynchttpClient提交表单上传图片,发现存在上传多张图片,会少上传一两张的情况,貌似是这框架的BUG;

改用xUtil可以成功上传;

 String ordernum = model.getOrdernum();
String username = model.getUsername();
RequestParams params = new RequestParams();
params.addBodyParameter("ordernum",ordernum);
params.addBodyParameter("username",username);
for(int i=0; i<filesList.size();i++){
params.addBodyParameter("images[" + i + "]",filesList.get(i));
Log.i(MyConfig.TagPic,"打印准备上传的图片资料流:"+filesList.get(i).getPath());
}
HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.POST, MyConfig.urlDataUpload, params,
new RequestCallBack<String>() { @Override
public void onSuccess(ResponseInfo<String> responseInfo) {
Log.i("main","当前结果:"+responseInfo.result);
mDialog.dismiss();
netTask();
isUpload = false;
hasCompress = false;
mSelectPath.clear();
filesList.clear();
mHashMapCompress.clear();
adapter.notifyDataSetChanged();
tv_right_submit.setEnabled(true);
//删除手机下面的小图片
if(!MyConfig.OpenDebugging){
FileUtil.deleteFileDir(MyConfig.PicFileSmallDir,false);
}
} @Override
public void onLoading(long total, long current, boolean isUploading) {
super.onLoading(total, current, isUploading);
int count = (int) ((current * 1.0 / total) * 100);
// 上传进度显示
progressBar.setProgress(count);
tv_progress.setText("正在上传资料....."+count+"%");
Log.i("上传 Progress>>>>>", "count="+count+"--"+current + " / " + total);
} @Override
public void onFailure(HttpException e, String s) {
mDialog.dismiss();
}
});

附:thinkphp接口:

 //上传资料
public function upload()
{
$config = array(
//'rootPath' => 'E:/phpStudy/www/yne_siteM/uploads/scan/'.'file/',
'rootPath' => 'D:/www/yne_siteM/uploads/scan/'.'file/',
);
$upload = new \Think\Upload($config);
// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath = 'imgs'; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{
// 上传成功 获取上传文件信息
foreach($info as $file){
echo $file['savepath'].$file['savename']; $db = M('order');
$data['materialurl'] = 'uploads/scan/file/'.$file['savepath'].$file['savename'];
$where['username'] = $_POST['username'];
$where['ordernum'] = $_POST['ordernum'];
$da = $db->field('materialurl')->where($where)->select();
if($da){
$datas['materialurl'] = $da[0]['materialurl'].'|'.$data['materialurl'];
$tis = $db->where($where)->save($datas);
}else{
$tis = $db->where($where)->save($data);
}
}
}
/*$db1 = M('order');
$d = $db1->field('materialurl')->where($where)->select();*/
if($tis){
$response['status'] = 'Y';
$response['msg'] = '成功';
$response['data'] = $tis;
echo json_encode($response);
}else{
$response['status'] = 'N';
$response['msg'] = '失败';
echo json_encode($response);
}
// $this->ajaxReturn(true); // "file"名字必须和iOS客户端上传的name一致
/*if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "imagepeg"))
{
if ($_FILES["file"]["error"] > 0) {
echo $_FILES["file"]["error"]; // 错误代码
} else {
$fillname = $_FILES['file']['name']; // 得到文件全名
$dotArray = explode('.', $fillname); // 以.分割字符串,得到数组
$type = end($dotArray); // 得到最后一个元素:文件后缀 $path = "E:/phpStudy/www/yne_siteM/uploads/scan/".md5(uniqid(rand())).'.'.$type; // 产生随机唯一的名字 move_uploaded_file( // 从临时目录复制到目标目录
$_FILES["file"]["tmp_name"],$path);
echo "成功";
}
} else {
echo "文件类型不正确";
}*/
}

最新文章

  1. ASP.NET MVC5+EF6+EasyUI 后台管理系统(64)-补充WebApi与Unity注入-配置文件
  2. 工厂方法模式与IoC/DI
  3. eclipse中英文切换--四种方式
  4. 研究系统IO和glib IO的关系
  5. [GRYZ2015]足球联赛
  6. iOS调用系统通讯录获取姓名电话号码(转)
  7. [转]怎样在cmd(命令提示符)下进行复制粘贴操作
  8. linux下包管理命令yum与apt-get以及开发环境配置
  9. React Native for android 项目驱动教程
  10. Python爬虫之ip代理池
  11. ReentrantLock重入锁详解
  12. makefile笔记7 - makefile函数
  13. 再谈spring的循环依赖是怎么造成的?
  14. Git 撤销所有未提交(Commit)的内容
  15. $Django 多表操作(增删改查,基于双下划线,对象的查询) 在Python脚本中调用Django环境
  16. Intellij IDEA使用Docker插件部署应用
  17. 使用npm install时一直报错-4048 operation not permitted
  18. 关于Spring MVC跨域
  19. Catogory如何添加属性
  20. ocv &amp; derate &amp; crpr

热门文章

  1. zzuliOJ 1904小火山的股票交易;
  2. Spark 机器学习
  3. [z]vs中无法加入断点进行调试的解决方案
  4. sublime txt 设置在浏览器预览
  5. handlebars
  6. 2.Unable to instantiate Action, templateAction, defined for &#39;template_list&#39; in namespace &#39;/&#39;templateAction
  7. [转]MySQL主从复制原理介绍
  8. jsp_设置文件编码
  9. utime函数
  10. [f]区间随机数函数