网络框架:Okhttp+Retrofit
API:
@Multipart
@POST("upload/uploadFiles.do")
Call<JsonObject> uploadFile(@Part List<MultipartBody.Part> list);
代码中调用:
private void uploadFile(String taskId){
List<MultipartBody.Part> partList = new ArrayList<>();
for (String filePath : fileList) {
File file = new File(filePath);
RequestBody request = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), request);
partList.add(body);
}
Call<JsonObject> call = MyApplication.service.uploadFile(partList);
MyApplication.getInstance().clientTask.executeJsonObject(taskId,call,this,true);
}