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 "文件类型不正确";
}*/
}

asynchttpClient框架关于多文件批量上传的问题,改用xUtil的更多相关文章

  1. 文件批量上传-统一附件管理器-在线预览文件(有互联网和没有两种)--SNF快速开发平台3.0

    实际上在SNF里使用附件管理是非常简单的事情,一句代码就可以搞定.但我也要在这里记录一下统一附件管理器能满足的需求. 通用的附件管理,不要重复开发,调用尽量简洁. 批量文件上传,并对每个文件大小限制, ...

  2. SpringMVC+Ajax实现文件批量上传和下载功能实例代码

    需求: 文件批量上传,支持断点续传. 文件批量下载,支持断点续传. 使用JS能够实现批量下载,能够提供接口从指定url中下载文件并保存在本地指定路径中. 服务器不需要打包. 支持大文件断点下载.比如下 ...

  3. 带进度条的文件批量上传插件uploadify

    有时项目中需要一个文件批量上传功能时,个人认为uploadify是快速简便的解决方案. 先上效果图: 一. 下载uploadify 从官网下载uploadify的Flash版本(Flash版本免费,另 ...

  4. 文件批量上传的工具,要实现暂停继续、断点续传等功能(使用QtNetwork和QHttpMultiPart,和定时器检查超时)

    最近在做一个文件批量上传的工具,要实现暂停继续.断点续传等功能.利用Qt自带的QtNetwork模块,完成这些需求并没有费多少周章,主要思路就是将文件分块,然后用while循环依次传输.具体实现代码比 ...

  5. 使用WebUploader实现文件批量上传,进度条显示功能

    知识点:利用WebUploader,实现文件批量上传,并且实时显示文件的上传进度 参考官方文档:http://fex.baidu.com/webuploader/ (1)引入三个资源 JS,CSS,S ...

  6. jquery文件批量上传控件Uploadify3.2(java springMVC)

    人比較懒  有用为主 不怎么排版了 先放上Uploadify的官网链接:http://www.uploadify.com/  -->里面能够看到PHP的演示样例,属性说明,以及控件下载地址.分f ...

  7. 利用uploadify+asp.net 实现大文件批量上传。

    前言 现在网上文件上传组件随便一搜都是一大堆,不过看大家一般都在用uploadify这个来上传文件.由于项目需要,我在来试了一下.因为第一次使用,也遇到了很多问题,特此记录! ------------ ...

  8. uploadify文件批量上传

    uploadify能够时间文件的批量上传,JS文件包下载地址,使用说明可以参考官网文档(http://www.uploadify.com/documentation/) 使用方法如下代码: $(&qu ...

  9. 关于在Struts2框架下实现文件的上传功能

    struts2的配置过程 (1)在项目中加入jar包 (2)web.xml中filter(过滤器)的配置 <?xml version="1.0" encoding=" ...

随机推荐

  1. iOS获取当前app的名称和版本号

    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary); // ap ...

  2. CWebBrowser2获取html的内容

    m_web为浏览器控件的变量名 LPDISPATCH p=m_web.GetDocument(); CComQIPtr<IHTMLDocument2,&IID_IHTMLDocument ...

  3. POJ 1742 Coins DP 01背包

    dp[i][j]表示前i种硬币中取总价值为j时第i种硬币最多剩下多少个,-1表示无法到达该状态. a.当dp[i-1][j]>=0时,dp[i][j]=ci; b.当j-ai>=0& ...

  4. 【转】进程与CPU

    声明:本博客转自:http://blog.chinaunix.net/uid-20737871-id-1881246.html 简单地说,CPU 亲和性(affinity) 就是进程要在某个给定的 C ...

  5. iOS多线程编程指南(二)线程管理

    当应用程序生成一个新的线程的时候,该线程变成应用程序进程空间内的一个实体.每个线程都拥有它自己的执行堆栈,由内核调度独立的运行时间片.一个线程可以和其他线程或其他进程通信,执行I/O操作,甚至执行任何 ...

  6. Java入门1dayCode

    public class HelloWorld { /* * 多行注释方式 * main()方法: java语言的入口方法(函数) */ public static void main(String[ ...

  7. 如何查看 oracle 官方文档

    Concept 包含了 oracle 数据库里面的一些基本概念和原理, 比如 数据库逻辑结构, 物理结构, 实例结构, 优化器, 事务等. PDF 460页 Reference 包含了动态性能视图, ...

  8. Windows 8.1 应用再出发 - 视图状态的更新

    本篇我们来了解一下Windows 8.1 给应用的视图状态带来了哪些变化,以及我们怎么利用这些变化作出更好的界面视图. 首先我们来简单回顾一下Windows 8.0 时代的视图状态:     上图中, ...

  9. nginx实现访问网站或目录密码认证保护

    添加目录登陆认证 location / { auth_basic "提示"; auth_basic_user_file /usr/conf/htpasswd; } auth_bas ...

  10. LDO-BD00C0AWFP

    BD00C0AWxx  1.该产品是ROHM公司的一款高输入电压可达26.5V,输出电压可达15V,输出电流1A的LDO.具有较低的ESR Capacitor. 2.输入电压变化4-26.5V,输出3 ...