The above screenshot contain the Post method and Response from the server.. here i am trying to upload an image with some data to my server(catch the image from gallery or camera)..
I am trying to achieve this via retrofit2. trying some methods from Internet... but i can't get the right way to done it
new in retrofit2. so I cant done this.
How to Create retrofit2 interface and handle the response.. please help
Edit My Try
Code in Activity
ProofAPI service = retrofit.create(ProofAPI.class);
File file=new File(sdCard.getAbsolutePath()+fNameAd);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("proof", file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
HashMap<String, String> map = new HashMap<>();
map.put("userId", user_id);
map.put("proofDocId", idproofno);
map.put("proofFilename", proofFilename);
map.put("docType", docType);
Call<ProofResp> call = service.uploadFileWithPartMap(map,filePart);
call.enqueue(new Callback<ProofResp>() {
@Override
public void onResponse(Call<ProofResp> call, Response<ProofResp> response) {
Toast.makeText(getApplicationContext(),response.body().getMessage(),Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<ProofResp> call, Throwable t) {
Toast.makeText(getApplicationContext(),"fjkds",Toast.LENGTH_SHORT).show();
}
});
Retofit2 Interface -> ProofAPI
@Multipart
@POST("rest-proof-upload")
Call<ProofResp> uploadFileWithPartMap(
@PartMap() Map<String, String> partMap,
@Part MultipartBody.Part file
);
and I get the failure message. Is this the right way .. Anyone please explain the correct way to achive it.