Re: [android-developers] Upload image file to server

2010-12-28 Thread Abhilash baddam
Hi naveen,

Go through this link may be it'l be useful..

http://androidsnips.blogspot.com/2010/08/upload-file-to-remote-server-in-android.html





Regards,
Abhilash.B

On Tue, Dec 28, 2010 at 4:42 PM, naveen kumar
wrote:

> 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(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 ofbytesSent-->"+
> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Upload image file to server

2010-12-28 Thread naveen kumar
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(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 ofbytesSent-->"+
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en