最近做项目涉及到图片上传这块,多张图片上传是用xutils实现的,图片选择、预览是参考了微信图片选择的demo,先上图:
这是网上参考了仿微信图片上传实现的,这里就不多讲了,文章底部有下载链接,下面介绍下关于多张图片上传,主要基于xutils实现:
</pre><pre name="code" class="java">private String uploadHost="后台URL"; //服务器接收地址 private List<imgPath> list; //存放图片地址 RequestParams params=new RequestParams(); for(int i = 0; i < imgList.size(); i++){ //key+i为上传的参数,后面为图片路径 params.addBodyParameter("key" + i , new File(list.get(i))); } uploadMethod(params,uploadPath);
<pre name="code" class="java">public void uploadMethod(final RequestParams params,final String uploadHost) {HttpUtils http = new HttpUtils();http.send(HttpMethod.POST, uploadHost, params,new RequestCallBack<String>() {@Overridepublic void onStart() {//msgTextview.setText("conn...");}@Overridepublic void onLoading(long total, long current,boolean isUploading) {if (isUploading) {} else {}}@Overridepublic void onSuccess(ResponseInfo<String> responseInfo) {//Photoceshi userInfo=JSON.parseObject(responseInfo.result,Photoceshi.class); //Toast.makeText(Photoceshi.this, "发送成功!", Toast.LENGTH_SHORT).show(); }@Overridepublic void onFailure(HttpException error, String msg) {//msgTextview.setText(error.getExceptionCode() + ":" + msg); //Toast.makeText(Photoceshi.this, "发送失败!"+msg, Toast.LENGTH_SHORT).show(); System.out.println("error:"+msg);}});}
代码 多图上传只是举了个例子,如有问题可回复