I want to send a post request in which I've to send some data which includes json formatted data and a image file.
When I'm sending request separately then its working fine, but does'nt wokring together.
Please help me here, how to acheive this.
What I've used for sending json formatted data:
Map<String, String> map = new HashMap<>();
postParam.put("title", "XYZ");
postParam.put("isGroup", "true");
postParam.put("ownerId", "123");
JSONArray jsonArray = new JSONArray();
jsonArray.put("1");
jsonArray.put("2");
jsonArray.put("2");
postParam.put("groupMembers", jsonArray.toString());
MediaType JSON = MediaType.parse("application/json");
JSONObject parameter = new JSONObject(postParam);
RequestBody body = RequestBody.create(JSON, parameter.toString());
Request request = new Request.Builder()
.url(postUrl)
.addHeader("content-type", "application/json; charset=utf-8")
.post(body)
.build();
Its working fine when I've not used the file. But I've to send a image file as multipart data with this request, then how to do it.