String apiUrl = cloudinary.cloudinaryApiUrl(action, options);
HttpClient client = new DefaultHttpClient();
HttpPost postMethod = new HttpPost(apiUrl);
MultipartEntity multipart = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
// Remove blank parameters
for (Map.Entry<String, Object> param : params.entrySet()) {
if (param.getValue() instanceof String) {
String value = (String) param.getValue();
if (StringUtils.isNotBlank(value)) {
multipart.addPart(param.getKey(), new StringBody(value));
}
} else if (param.getValue() instanceof Collection) {
for (Object value : (Collection) param.getValue()) {
multipart.addPart(param.getKey()+"[]", new StringBody(Cloudinary.asString(value)));
}
}
}
if (file instanceof String && !((String) file).matches("^https?:.*")) {
file = new File((String) file);
}
if (file instanceof File) {
multipart.addPart("file", new FileBody((File) file));
} else if (file instanceof String) {
multipart.addPart("file", new StringBody((String) file));
}
postMethod.setEntity(multipart);
HttpResponse response = client.execute(postMethod);
int code = response.getStatusLine().getStatusCode();