Image upload sending no content

All your problems with Audio, Video and Images.

Image upload sending no content

Postby jr83 » Fri Feb 18, 2011 10:48 am

Hi,
I've tried a few solutions to get my device to send an image via httppost but each time there does not seem to be any content being sent.
I have two samples of code that I have tried but both create blank files when the web service is invoked:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String url = "MYURL";
  2.                 HttpClient httpClient = new DefaultHttpClient();
  3.                
  4.          try {
  5.                          httpClient.getParams().setParameter("http.socket.timeout", new Integer(90000)); // 90 second
  6.                  HttpPost post = new HttpPost(url);
  7.                  File SDCardRoot = Environment.getExternalStorageDirectory();
  8.                          File file = new File(SDCardRoot,"/DCIM/100MSDCF/DSC00004.jpg");
  9.                  FileEntity entity;
  10.                  entity = new FileEntity(file,"binary/octet-stream");
  11.                  entity.setChunked(true);
  12.                  post.setEntity(entity);
  13.                  post.addHeader("Header", "UniqueName");
  14.                  HttpResponse response = httpClient.execute(post);
  15.                  if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
  16.                          Log.e("Here","--------Error--------Response Status line code:"+response.getStatusLine());
  17.                  }else {
  18.                          // Here every thing is fine.
  19.                  }
  20.                
  21.                  HttpEntity resEntity = response.getEntity();
  22.                  if (resEntity == null) {
  23.                          Log.e("Here","---------Error No Response!!-----");
  24.                  }
  25.          } catch (Exception ex) {
  26.                  Log.e("Here","---------Error-----"+ex.getMessage());
  27.                  ex.printStackTrace();
  28.          } finally {
  29.                    httpClient.getConnectionManager().shutdown();
  30.          }
  31.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


The second is as follows:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String url = "MYURL";
  2.                 //File SDCardRoot = Environment.getExternalStorageDirectory();
  3.                 File file = new File(Environment.getExternalStorageDirectory(),"/DCIM/100MSDCF/DSC00004.jpg");
  4.                 try {
  5.                         HttpClient httpclient = new DefaultHttpClient();
  6.                         HttpPost httppost = new HttpPost(url);
  7.                         InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1);
  8.                         reqEntity.setContentType("binary/octet-stream");
  9.                         reqEntity.setChunked(true);
  10.                         // Send in multiple parts if needed
  11.                         httppost.setEntity(reqEntity);
  12.                         HttpResponse response = httpclient.execute(httppost);
  13.                         Log.d("finishing", "The try catch function");
  14.                 } catch (Exception e) {
  15.                         // show error
  16.                 }
  17.  
  18.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

As you can see I have hardcoded in an image for the file to try and get this working but no content is being sent.
Am I missing something? like setContent? I'm not sure on this.
Would be grateful if someone could help.
Thanks,
jr83
jr83
Junior Developer
Junior Developer
 
Posts: 12
Joined: Thu Sep 16, 2010 5:21 pm

Top

Re: Image upload sending no content

Postby maverickARM » Mon Feb 21, 2011 11:26 am

try use additional libraries
apache mime
httpclient
mime4j and so on...
google it1 u will find it easy! :)
User avatar
maverickARM
Freshman
Freshman
 
Posts: 3
Joined: Mon Feb 21, 2011 11:09 am

Re: Image upload sending no content

Postby mariFio » Thu Apr 28, 2011 11:36 am

Hi all,
i've got the same problem, have you resolved?
On the server, have you got something like a .jso file or a .php file that saves the image?
let me know please,
MF
mariFio
Freshman
Freshman
 
Posts: 3
Joined: Thu Apr 28, 2011 11:32 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests