I am trying to upload an image from the android application to drupal. On drupal I have enabled the services module with rest server. My endpoint is androidrpc-endpoint. I have loged in successfully. However, now I am getting the error ( ["CSRF validation failed"] of type org.json.JSONArray cannot be converted to JSONObject). If anyone could point out the rror or give a me a tutorial to follow.
String filePath = "mnt/sdcard/application/AboutUS.jpg";
Bitmap bm = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArrayImage = baos.toByteArray();
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
HttpPost httpPost = new HttpPost("http://drupal/androidrpc-endpoint/file")
JSONObject json = new JSONObject();
JSONObject fileObject = new JSONObject();
try {
fileObject.put("file", encodedImage);
fileObject.put("filename", "AboutUS");
fileObject.put("uid",1);
fileObject.put("filepath", filePath);
json.put("file", fileObject);
StringEntity se = new StringEntity(json.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpPost.setEntity(se);
//send the POST request
HttpResponse response = httpclient.execute(httpPost);
//read the response from Services endpoint
String jsonResponse = EntityUtils.toString(response.getEntity());
JSONObject jsonObject = new JSONObject(jsonResponse);//here is the error
int fid;
fid= jsonObject.getInt("fid");
return null;
}
catch(Exception e){
e.printStackTrace();
}
Any help please