Muhammad
Muhammad

Reputation: 137

Retrofit send base64 image in request

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);

Post man request screenshot

Upvotes: 1

Views: 4483

Answers (1)

Stephan John
Stephan John

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

Related Questions