A very simple approach for the dev who just want to send POST parameters in multipart request.
Make the following changes in class which extends Request.java
First define these constants :
String BOUNDARY = "s2retfgsGSRFsERFGHfgdfgw734yhFHW567TYHSrf4yarg"; //This the boundary which is used by the server to split the post parameters.
String MULTIPART_FORMDATA = "multipart/form-data;boundary=" + BOUNDARY;
Add a helper function to create a post body for you :
private String createPostBody(Map<String, String> params) {
StringBuilder sbPost = new StringBuilder();
if (params != null) {
for (String key : params.keySet()) {
if (params.get(key) != null) {
sbPost.append("\r\n" + "--" + BOUNDARY + "\r\n");
sbPost.append("Content-Disposition: form-data; name=\"" + key + "\"" + "\r\n\r\n");
sbPost.append(params.get(key).toString());
}
}
}
return sbPost.toString();
}
Override getBody() and getBodyContentType
public String getBodyContentType() {
return MULTIPART_FORMDATA;
}
public byte[] getBody() throws AuthFailureError {
return createPostBody(getParams()).getBytes();
}