/**
* 多图上传
*/
Map<String, RequestBody> requestBodyMap = new HashMap<>();
for (int i = 0; i < fileNames.size(); i++) {
File file = new File(fileNames.get(i));
RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), file);
// 这里前面一部分是服务器要求传的key("file"),加上一个i,就可以动态设置key的长度
requestBodyMap.put("file" + i + "\"; filename=\"" + file.getName(), requestBody);
}
Observable<Response<Void>> observable = BaseUrlApi.getApiBaseService().uploadFile(requestBodyMap, feedbackBean.getId(), 0);
HttpMethods.toSubscribe(observable, new BaseObserver<Response<Void>>(getSupportFragmentManager()) {
@Override
protected void onBaseNext(Response<Void> data) {
commitSuccess();
}
@Override
protected void onBaseError(Throwable t) {
super.onBaseError(t);
}
});
}
/**
* 多图上传接口
*/
@Multipart
@POST("feedbacks/uploadFile")
Observable<Response<Void>> uploadFile(@PartMap Map<String, RequestBody> requestBodyMap, @Query("feedbackId") int feedbackId, @Query("fileType") int fileType);
https://blog.csdn.net/danceinkeyboard/article/details/78096926
网友评论