![](/img/trans.png)
[英]I want to save both image and string data on the server by using retrofit multipart but I am getting an error
[英]i want to upload images using multipart to backend using retrofit in android. i am getting 500 error whie it works in postman
我使用的端點
@Multipart @POST("upload/{id}") 調用 uploadmultipleIdentityImages(@Path("id") int customerId, @Part MultipartBody.Part file1, @Part MultipartBody.Part file2 );
上傳方法..
嘗試 {
** f1 = 新文件(getPath(istImageuri)); ** f2 = 新文件(getPath(sndImageuri));
RequestBody requestFile1 =
RequestBody.create(MediaType.parse("multipart/form-data"), f1);
RequestBody requestFile2 = RequestBody.create(MediaType.parse("multipart/form-data"), f2);
//create multipartbody for ist image
MultipartBody.Part body1 = MultipartBody.Part.createFormData("Work_id", f1.getName(),requestFile1);
Log.e("docUploadfrag->", "Second Request Body");
//create multipartbody for 2nd image
MultipartBody.Part body2 = MultipartBody.Part.createFormData("Bank_statement", f2.getName(),requestFile2);
if (body1 != null && body2 != null) {
Log.e("docUploadfrag ->", "Body 1& Body 2");
Call<udRes> resCall = connectuser.uploadmultipleIdentityImages(getCusid, body1, body2);
resCall.enqueue(new Callback<udRes>() {
@Override
public void onResponse(Call<udRes> call, Response<udRes> response) {
if (response.isSuccessful()) {
Toast.makeText(getContext(), response.body().getStatus(), Toast.LENGTH_LONG).show();
Log.e("docUploadfrag1", response.body().getStatus());
} else {
Toast.makeText(getContext(), "There is an error", Toast.LENGTH_LONG).show();
Log.e("docUploadfrag1", String.valueOf(response.code()) + " " + response.message());
}
}
@Override
public void onFailure(Call<udRes> call, Throwable t) {
Toast.makeText(getContext(), "Please try again later ", Toast.LENGTH_LONG).show();
Log.e("docUploadfrag11", t.getMessage());
}
});
}
} catch (Exception e) {
Log.e("docUploadfrager _>", e.getMessage());
e.printStackTrace();
}
** 錯誤 ** 8022-8022/com.afarapartners.labalaba E/docUploadfrag1: 500 內部服務器錯誤
已經解決了。 Multipart 主體具有應該發送到服務器的錯誤對象名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.