2

I am trying to upload an image file using http-client from my Google Glass to my server but it always gets stuck at the httpclient.execute() method. I am not sure how should I approach uploading files from my Glass. This is what I have so far:

httpClient  = HttpUtils.getNewHttpsClient();
postRequest = new HttpPost(strURL);  

final File file= new File("mnt/sdcard/DCIM/Camera/12232.jpg"); 
s = new StringBuilder(); 
try
{

    if(file.exists())
    {           
        final FileBody bin = new FileBody(file);  
        final MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        reqEntity.addPart("uid", new StringBody(username,Charset.forName("UTF-8")));    
        reqEntity.addPart("pwd", new StringBody(password,Charset.forName("UTF-8")));

        if(encKey!=null && !encKey.equals(""))
            reqEntity.addPart("pvtkey", new StringBody(encKey,Charset.forName("UTF-8")));

        reqEntity.addPart("p", new StringBody(selectedDrivePath,Charset.forName("UTF-8")));
        reqEntity.addPart("ornt", new StringBody(fornt,Charset.forName("UTF-8")));
        reqEntity.addPart("file_size", new StringBody(strfilesize,Charset.forName("UTF-8")));
        reqEntity.addPart("data", bin);

        contentLength=reqEntity.getContentLength();
        postRequest.setEntity(reqEntity); 

        final HttpResponse response  = httpClient.execute(postRequest);
        ...
    }
    ...
}
...

Where am I going wrong?

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
  • Have you requested the `INTERNET` permission, and are you making the request in a background thread and not in the UI thread? – Tony Allevato Jan 18 '14 at 23:17
  • @TonyAllevato ya i am using internet permission as well as everything runs in the service with in a asynctask.Is there something else i need to add. – android_prp Jan 19 '14 at 03:18
  • I just noticed that your path is `"mnt/sdcard/DCIM/Camera/12232.jpg"`, which would be relative to whatever directory your app is running in. Shouldn't it be `"/mnt/..."`? – Tony Allevato Jan 19 '14 at 03:26
  • @TonyAllevato i am sorry the path starts with "/mnt/sdcard", it was just a typo. – android_prp Jan 19 '14 at 03:48
  • I am able to fix the issue..thank u all – android_prp Jan 26 '14 at 01:28
  • What did you do to "fix" the problem? – ErstwhileIII Feb 09 '14 at 15:19
  • @android_prp I have the same problem. How did you fix it? If you have a solution for your own problem on stackoverflow, please submit an answer yourself and mark it as correct. It could help others. – ocramot Jun 18 '14 at 08:24

1 Answers1

0

You may want to ensure you have reviewed the following description for media uploading. from the developer site for Google Glass.

I know this is basic (many stack*overflow* community members prefer that you already have researched a problem before posting here), so you really should visit https://developers.google.com/glass.

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37