One of my API
use multipart/form-data
to upload file and text in request body. How to code that like Postman
?
Asked
Active
Viewed 318 times
-1

Hasan Kucuk
- 2,433
- 6
- 19
- 41

sMARTheartz
- 61
- 1
- 6
-
Please try this https://stackoverflow.com/questions/16797468/how-to-send-a-multipart-form-data-post-in-android-with-volley – Vishal Sojitra Jun 22 '19 at 05:43
-
Follow this - https://stackoverflow.com/questions/56406730/how-to-upload-profile-pic-of-a-user-using-multipart-form-data/56439668#56439668 – Sanwal Singh Jun 22 '19 at 05:51
-
Possible duplicate of [How to send a “multipart/form-data” POST in Android with Volley](https://stackoverflow.com/questions/16797468/how-to-send-a-multipart-form-data-post-in-android-with-volley) – Swati Jun 22 '19 at 06:01
1 Answers
-1
VolleyMultipartRequest multipartRequest = new VolleyMultipartRequest(Request.Method.POST, url, new Response.Listener<NetworkResponse>() {
@Override
public void onResponse(NetworkResponse response) {
String resultResponse = new String(response.data);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("api_token", "gh659gjhvdyudo973823tt9gvjf7i6ric75r76");
params.put("name", "Angga");
return params;
}
@Override
protected Map<String, DataPart> getByteData() {
Map<String, DataPart> params = new HashMap<>();
params.put("imageName", new DataPart("file_image.jpg", AppHelper.getFileDataFromDrawable(getBaseContext(), mAvatarImage.getDrawable()), "image/jpeg"));
return params;
}
};
VolleySingleton.getInstance(getBaseContext()).addToRequestQueue(multipartRequest);

Dhara Jani
- 461
- 3
- 10
-
1This code has zero instructions or context to it. For example where are you getting AppHelper from? Or VolleySingleton? If you just simply copy and paste this code it doesn't work, so that is why you should always explain and break down your answers. – Jayce Nov 04 '19 at 05:01