xutils3 上传文件操作——个人小计
上传文件注意:
使用KeyValue对象进行添加文件操作
int uid = 2;
//普通字段的存储
requestParams.addBodyParameter("uid", String.valueOf(uid));
requestParams.addBodyParameter("content", context);
//创建keyValue集合进行存储File
List<KeyValue> list = new ArrayList<>();
if (mImagePathList != null && mImagePathList.size() > 1) {
Log.e("Activity", "需要执行上传文件功能");
for (String imgPath : mImagePathList) {
if (imgPath.equals(IMG_ADD_TAG)) {
continue;
}
File file = new File(imgPath);
list.add(new KeyValue("file", file));
}
MultipartBody body = new MultipartBody(list, "UTF-8");
requestParams.setRequestBody(body);