方案:
解决的方法是:使用Retrofit的MulipartTypedOutput
接口声明如下,注意此时不要再使用@FormUrlEncoded 和 @Multipart 注解了
@POST(PATH + "submitOrderExt.do") public void submitOrderMul(@Body MultipartTypedOutput multipartTypedOutput, BaseCallback<BaseCallbackModel> baseCallback);
MulipartTypedOutput 参数的装配示例代码如下:
/// 新的实现demo MultipartTypedOutput multipartTypedOutput = new MultipartTypedOutput(); multipartTypedOutput.addPart("stID", new TypedString(stID)); multipartTypedOutput.addPart("stName", new TypedString(stName)); multipartTypedOutput.addPart("uID", new TypedString(uID)); multipartTypedOutput.addPart("uLoginMail", new TypedString(uLoginMail)); multipartTypedOutput.addPart("areaID", new TypedString(areaID)); multipartTypedOutput.addPart("areaName", new TypedString(areaName)); multipartTypedOutput.addPart("oUserName", new TypedString(oUserName)); multipartTypedOutput.addPart("oUserTel", new TypedString(oUserTel)); multipartTypedOutput.addPart("oAddress", new TypedString(oAddress)); multipartTypedOutput.addPart("oRepairContent", new TypedString(oRepairContent)); multipartTypedOutput.addPart("oTimeStart", new TypedString(mTimeStart)); multipartTypedOutput.addPart("oTimeEnd", new TypedString(mTimeEnd)); for (Map.Entry<String, Uri> entry : oSceneImgUriMap.entrySet()) { multipartTypedOutput.addPart("oSceneImg", new TypedFile("image/jpeg", new File(GetPathFromUri4kitkat.getPath(OrderActivity.this, entry.getValue())))); } if(null != voiceFile){ multipartTypedOutput.addPart("oVoice", voiceFile); }
说明:
有说Retrofit 2.0.0-beta1 之后 MultipartTypedOutput 不再使用转而使用@PartMap
Updates
MultipartTypedOutput no longer exists in Retrofit 2.0.0-beta1
For those who want to upload multiple images now can use with @PartMap, reference link javadoc