1. 程式人生 > >xutils3 上傳檔案操作——個人小計

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);