Dear sir,
Good evening
i am posting some string data with image but image is not uploading
plz help me how to code for upload image on server
My code
public void PostCameraData(){
httppost = new HttpPost(Splash.globalurl+"iphone/ads/response");
httpclient = new DefaultHttpClient();
//image sending code
String filepath = "/sdcard/RRImages/";
File imagefile = new File(filepath + ""+path);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
System.out.println("The value of byte data is>>>"+data);
//calculating time for post on server
long msTime = System.currentTimeMillis();
Date curDateTime = new Date(msTime);
String currentTime1=""+curDateTime;
//getting id
String id=RoadDetails.idD;
// Adding parameters to send to the HTTP server.
nameValuePairs = new ArrayList<NameValuePair>(7);
nameValuePairs.add(new
BasicNameValuePair("udid",SigninActivity.deviceid));
nameValuePairs.add(new BasicNameValuePair("sess_id",
SigninActivity.sessionidValue));
nameValuePairs.add(new BasicNameValuePair("thought", "thought"));
nameValuePairs.add(new BasicNameValuePair("comment", "comment"));
nameValuePairs.add(new BasicNameValuePair("ID", id));
nameValuePairs.add(new BasicNameValuePair("time", "101227124545"));
//nameValuePairs.add(new BasicNameValuePair("image", new
String(data)));
// Send POST message with given parameters to the HTTP server.
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
System.out.println("the value of response-->"+response);
InputStream is = response.getEntity().getContent();
System.out.println("the value of is-->"+is);
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);
int current = 0;
while((current = bis.read()) != -1)
{
baf.append((byte)current);
}
bytesSent = new String(baf.toByteArray());
System.out.println("the value of bytesSent-->"+
bytesSent);
}
catch (Exception e) {
// Exception handling
Log.e("Error",""+e);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en