Reputation: 137
I am sending a request from android using retrofit with content-type (form-data), request includes some strings and a base64 image property but it is not receiving on the server while using postman it is working.
I have tried different approaches using retrofit but data is not mapping on the server-side while it is working with the postman.
Retrofit call:
@POST("some-endpoint")
Call<DocumentResponse> postC(@Body RequestBody body);
Rertofit call preparation:
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("image", model.getImage())
.addFormDataPart("barcode", model.getBarcode())
.addFormDataPart("comment", model.getComment())
.addFormDataPart("type", model.getType())
.build();
Call<DocumentResponse> call = apiInterface.postC(requestBody);
Upvotes: 1
Views: 4483
Reputation: 331
While uploading the large size of data like image and other files using retrofit you need to use multipart annotation refer this link you can get the idea : How to Upload Image file in Retrofit 2
Upvotes: 1