关于asynchttpclient框架的post 提交表单上传文件怎么弄

关于asynchttpclient框架的post 提交表单上传文件怎么弄,第1张

1.添加权限(访问网络权限和读写权限)

2.获衫樱取上瞎模传文件路径并判断是否为空

3.若不为空,创磨塌缓建异步请求对象

4.创建上传文件路径

5.执行post请求(指定url路径,封装上传参数,新建AsyncHttpResponseHandler方法)

直接实例化多个file传到params里面配搜就可以了

RequestParams params = new RequestParams()

for (int i = 0i <list.size()i++) {

try {

params.put("培歼历images["改丛 + i + "]", new File(list.get(i)))

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace()

}

}

AreaHttpUtil.post(URL, params, new JsonHttpResponseHandler() {

@Override

public void onSuccess(int statusCode, JSONObject response) {

super.onSuccess(statusCode, response)

Toast.makeText(AreaApplication.context, "上传成功", Toast.LENGTH_SHORT).show()

}

@Override

public void onFailure(int statusCode, Header[] headers,

String responseBody, Throwable e) {

super.onFailure(statusCode, headers, responseBody, e)

Toast.makeText(AreaApplication.context, "上传失败", Toast.LENGTH_SHORT).show()

}

public void onProgress(int current, int count) {

System.out.println("帆败袭current " + current)

System.out.println("total " + count)

upload.setProgress((int) (current / (float) count * 100))

upload.setText(current / 1024 + "枯渣/"态兄 + count / 1024 + "K")

Message message = new Message()

message.obj = upload

message.what = 1

GlobalHandler.getHandler().sendMessage(message)

}

})


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12303428.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存