hi
i doing app for uploading image to php server from android and the php server return a url as response for the request. i checked no problem in php server side it works fine for iphone. but in android i cannot get response. i have checked the php server my image is not uploaded. i do not know what is the problem in the code and how to get response. Is there is any setting needed? my code :
public class upload extends Activity {
InputStream is;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Bitmap bitmapOrg = BitmapFactory.decodeFile("/sdcard/imageq.png");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.PNG, 90, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxxxxxxxxx/xxxxxx/upload.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("uri",""+httppost.getURI());
Log.e("response",""+response);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("is",""+is);
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
}
i get the above code from Android: Upload image to Server | SP Technolab Blog my log cat information:
05-11 10:09:39.488: ERROR/uri(1894): http://xxxxxxxxxx/xxxxxx/upload.php
05-11 10:09:39.488: ERROR/response(1894): org.apache.http.message.BasicHttpResponse@44f73610
05-11 10:09:39.495: ERROR/is(1894): org.apache.http.conn.EofSensorInputStream@44f1fc88
i print the getURI it returns what i give in the httppost = new HttpPost("...."). this is not real response from server. please help me.
i doing app for uploading image to php server from android and the php server return a url as response for the request. i checked no problem in php server side it works fine for iphone. but in android i cannot get response. i have checked the php server my image is not uploaded. i do not know what is the problem in the code and how to get response. Is there is any setting needed? my code :
public class upload extends Activity {
InputStream is;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Bitmap bitmapOrg = BitmapFactory.decodeFile("/sdcard/imageq.png");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(Bitmap.CompressFormat.PNG, 90, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new
ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxxxxxxxxx/xxxxxx/upload.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("uri",""+httppost.getURI());
Log.e("response",""+response);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("is",""+is);
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
}
i get the above code from Android: Upload image to Server | SP Technolab Blog my log cat information:
05-11 10:09:39.488: ERROR/uri(1894): http://xxxxxxxxxx/xxxxxx/upload.php
05-11 10:09:39.488: ERROR/response(1894): org.apache.http.message.BasicHttpResponse@44f73610
05-11 10:09:39.495: ERROR/is(1894): org.apache.http.conn.EofSensorInputStream@44f1fc88
i print the getURI it returns what i give in the httppost = new HttpPost("...."). this is not real response from server. please help me.