在Android中通过改造2.3.0发送多个图像时出现错误请求 [英] bad request while sending multiple images through retrofit 2.3.0 in android
本文介绍了在Android中通过改造2.3.0发送多个图像时出现错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾经通过翻新版2.3.0将多个图像发送到服务器, 但我收到了错误的请求(400 err0r) 我的代码:
I used to send multiple images to server through retrofit 2.3.0 , but I got bad request (400 err0r) my code:
ArrayList<MultiPartImagesInputData> multiImagesList = new ArrayList<>();
String[] multiplesImages = {"originalImgBlob", "img430Blog", "img200Blog", "img100Blog", "blurResponseBlob"};
for (int i = 0; i < mFiles.size(); i++) {
MultiPartImagesInputData multiPartImagesInputData = new MultiPartImagesInputData(multiplesImages[i], mFiles.get(i));
multiImagesList.add(multiPartImagesInputData);
}
并像这样创建多部分类型的数组:
and create multi part typed array like this:
MultipartBody.Part[] multipartTypedOutputle = new MultipartBody.Part[mFiles.size()];
for (int index = 0; index < mFiles.size(); index++) {
Log.d("Upload request", "requestUploadSurvey: survey image " + index + " " + mFiles.get(index));
// File file2 = new File(mResultBtmpProccess.get(index).path);
RequestBody surveyBody = RequestBody.create(MediaType.parse("image/png"), mFiles.get(index));
multipartTypedOutputle[index] = MultipartBody.Part.createFormData("imageFiles["+index+"]", multiImagesList.get(index).getFileName(), surveyBody);
}
这是服务器呼叫
RequestBody memberId1 = RequestBody.create(MediaType.parse("text/plain"), Singleton.getInstance().getUserRegDetailsRespModel().getMId());
RequestBody actionType1 = RequestBody.create(MediaType.parse("text/plain"), ACTION_TYPE_UPLOAD_NEW_PIC);
Call<JsonObject> stringCall = mServerUtilities.getStringClassService(getApplicationContext(), "").postImages(memberId1, actionType1, multipartTypedOutputle);
stringCall.enqueue(new retrofit2.Callback<JsonObject>() {
@Override
public void onResponse(Call<JsonObject> call, @NonNull retrofit2.Response<JsonObject> response) {
Log.d("fb_regist_response", "--->" + "" + response);
mUtilities.cancelProgressDialog();
}
@Override
public void onFailure(Call<JsonObject> call, Throwable t) {
mUtilities.cancelProgressDialog();
mUtilities.showAlert(t.getMessage(), getResources().getString(R.string.app_name));
Log.d("onFail_fb_regist_res", t.getMessage());
}
});
界面:
@PartMap Map<String, RequestBody> multipartTypedOutput);
@Multipart
@POST("/api/mbrphotos/prfImgIU/{memberId}/{actionType}")
Call<JsonObject> postImages(@Part("memberId") RequestBody memberId,
@Part("actionType") RequestBody actionType,
@Part MultipartBody.Part[] multipartTypedOutput);
我在这方面做错了什么?
what I did wrong in this ?
推荐答案
您编写的所有内容均正确无误,但API后端必须出错.请重新检查.对我来说,我签入了邮递员,尽管该API不允许通过手机触发,但它仍在上传.他们必须允许表单数据. :)希望您的问题能得到解决.
Everything which you have written correctly, but error must be in API backend. Please re-check it. For me I checked in postman it is being uploaded even though the API doesn't allowing when it is being fired by mobile. They must allow form-data. :) I hope your issue would be solved.
这篇关于在Android中通过改造2.3.0发送多个图像时出现错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文