Please help me to write the android code to upload the image to the server.
My server side code is
function uploadFiles( fileOrBlob ) {
var name = 'unspecified';
if (fileOrBlob['name']) {
name = fileOrBlob.name;
}
var xhr = new XMLHttpRequest();
xhr.open('POST', '/eskom/gallery/imagepost', true);
xhr.setRequestHeader('plxImgName', name);
xhr.setRequestHeader('plxName', 'Sean Williams');
xhr.setRequestHeader('plxEmail', 'email@address.com');
xhr.setRequestHeader('plxTel', '+25665567');
xhr.setRequestHeader('plxCompany', 'IBM');
xhr.onload = onload;
xhr.send(fileOrBlob);
}
My Android code
ByteArrayOutputStream bos = new ByteArrayOutputStream();
im_bitmap.compress(CompressFormat.JPEG, 60, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(url);
ByteArrayBody bab = new ByteArrayBody(data, simagename);
// File file= new File("/mnt/sdcard/forest.png");
// FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploaded", bab);
reqEntity.addPart("plxEmail", new StringBody("email@address.com"));
reqEntity.addPart("plxImgName", new StringBody(simagename));
reqEntity.addPart("plxName", new StringBody(pref.getString("username", "")));
reqEntity.addPart("plxTel", new StringBody("+27111234567"));
reqEntity.addPart("plxComany", new StringBody("IBM"));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((response = reader.readLine()) != null) {
s = s.append(response);
}
But the image is not uploading.. Also i am getting the error message that "Error during evaluation of resource template : POST gallery/imagepost/"
Thanks