I am trying to upload my pictures to Cloudinary using their REST API. The Cloudinary library from CN1 worked very well for me, but I am looking to control a few things like FailSilently and being able to addToQueue and addToQueueAndWait.
This is my code, where I take a picture using the camera and then I upload to Cloudinary, but it doesn't seem to work:
@Override
protected void onMain_ButtonSubirAPIAction(Component c, ActionEvent event) {
String picture = Capture.capturePhoto(width, -1);
if(picture!=null){
String cloudinaryURL = "https://api.cloudinary.com/v1_1/"+CLOUDNAME+"/image/upload";
MultipartRequest request = new MultipartRequest() {
protected void readResponse(InputStream input) throws IOException {
JSONParser jp = new JSONParser();
Map <String, Object> result = jp.parseJSON(new InputStreamReader(input, "UTF-8"));
labelX.setText((String)result.get("url"));
}
};
request.setPost(true);
request.setHttpMethod("POST");
String encoded = Base64.encodeNoNewline((APIKEY + ":" + APISECRET).getBytes());
request.addRequestHeader("Authorization", "Basic " + encoded);
request.setUrl(cloudinaryURL);
try {
request.addData("file", picture, "image/jpeg");
request.addArgument("public_id", "name1");
NetworkManager.getInstance().addToQueue(request);
} catch(Exception err) {
}
}
}
I have been trying to modify parameters indicated from their API documentation page: http://cloudinary.com/documentation/admin_api#usage_examples
Thanks
EDIT: Here is the syntax: