[android-developers] help on uploading image to server
Hi all, I am trying to upload image to php server but it is not up loading here is my following code public class ImageUpload extends Activity { Bitmap bm; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon); // bm = BitmapFactory.decodeFile(/sdcard/DCIM/forest.png); executeMultipartPost(); } catch (Exception e) { Log.e(e.getClass().getName(), e.getMessage()); } } public void executeMultipartPost() throws Exception { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost( http://ncpo.cc/android/uploadbespokecase.php;); // ByteArrayBody bab = new ByteArrayBody(data, icon.jpg); File file = new File(/sdcard/FB_loginnew.png); FileBody bin = new FileBody(file); MultipartEntity reqEntity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart(uploaded, bin); reqEntity.addPart(photoCaption, new StringBody(sfsdfsdf)); 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 ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } System.out.println(Response: + s); Log.d(Image up load, Response + s); bm.recycle(); } catch (Exception e) { // handle exception here Log.e(e.getClass().getName(), e.getMessage()); } } } Please any one help me . i am un able to find the errror. -- 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
Re: [android-developers] help on uploading image to server
hii http://blog.sptechnolab.com/2011/03/09/android/android-upload-image-to-server/ i think this url helps.. On Wed, Jan 25, 2012 at 11:52 AM, chowdary nani naveenneeli...@gmail.comwrote: Hi all, I am trying to upload image to php server but it is not up loading here is my following code public class ImageUpload extends Activity { Bitmap bm; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon); // bm = BitmapFactory.decodeFile(/sdcard/DCIM/forest.png); executeMultipartPost(); } catch (Exception e) { Log.e(e.getClass().getName(), e.getMessage()); } } public void executeMultipartPost() throws Exception { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost( http://ncpo.cc/android/uploadbespokecase.php;); // ByteArrayBody bab = new ByteArrayBody(data, icon.jpg); File file = new File(/sdcard/FB_loginnew.png); FileBody bin = new FileBody(file); MultipartEntity reqEntity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart(uploaded, bin); reqEntity.addPart(photoCaption, new StringBody(sfsdfsdf)); 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 ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } System.out.println(Response: + s); Log.d(Image up load, Response + s); bm.recycle(); } catch (Exception e) { // handle exception here Log.e(e.getClass().getName(), e.getMessage()); } } } Please any one help me . i am un able to find the errror. -- 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
Re: [android-developers] help on uploading image to server
In multiaprt http pst you need to pass the byte array , here you are passing the file body -- 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
Re: [android-developers] help on uploading image to server
Hi Ratheesh Valamchuzhy, Thanks for replay.Thanks for help .Thanks for time. will you please send me the code for it. Again thanks for time Thanks Naveen. On Wed, Jan 25, 2012 at 12:15 PM, Ratheesh Valamchuzhy android...@gmail.com wrote: In multiaprt http pst you need to pass the byte array , here you are passing the file body -- 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
Re: [android-developers] help on uploading image to server
Why not use a direct apache FTP Client. I am able to upload the files with the FTPClient. Warm Regards, *Mukesh Kumar*, Android Consultant/Freelancer, India,Hyderaba On Wed, Jan 25, 2012 at 12:15 PM, Ratheesh Valamchuzhy android...@gmail.com wrote: In multiaprt http pst you need to pass the byte array , here you are passing the file body -- 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 -- d. -- 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