// this is the relevant method
override fun getParams(): Map<String, String>? {
val params: MutableMap<String, String> = HashMap()
params["documents"] = arrayListOf<String>().toString()
return params
}
}
I want to pass the image parameters in my POST API call but I am unable to figure it out
CodePudding user response:
You need send the data in Multipart when the POST method involves the file. Check This
If you want to use Retofit check This
CodePudding user response:
You will have to make multipart request to the server. Below example may help you.
ApiInterface.java
@Multipart
@POST("addExpertImage")
Call<ImageUploadResponse> uploadImage(@Part MultipartBody.Part file,
@Part("user_email") RequestBody userEmail, @Part("server_id") RequestBody
serverId, @Part("folder_name") RequestBody folderName);
Network call
final File file = new File(imageData.getFilePath());
// create RequestBody instance from file
final RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body =
MultipartBody.Part.createFormData("image", file.getName(), requestFile);
RequestBody serverId = RequestBody.create(MediaType.parse("text/plain"), String.valueOf((Integer) imageData.getServerId()));
RequestBody userEmail = RequestBody.create(MediaType.parse("text/plain"), (String) PrefSettings.getInstance(context).get(Constants.USER_EMAIL));
RequestBody folderName = RequestBody.create(MediaType.parse("text/plain"), imageData.getFolderName());
Call<ImageUploadResponse> resultCall = ApiClient.getInstance().create(ApiInterface.class).uploadImage(body, userEmail, serverId, folderName);