【问题标题】:Google Glass upload files using http-clientGoogle Glass 使用 http-client 上传文件
【发布时间】:2014-01-18 20:49:01
【问题描述】:

我正在尝试使用 http-client 从我的 Google Glass 将图像文件上传到我的服务器,但它总是卡在 httpclient.execute() 方法上。我不知道应该如何从我的 Glass 上传文件。这是我目前所拥有的:

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);
        ...
    }
    ...
}
...

我哪里出错了?

【问题讨论】:

  • 您是否请求了INTERNET 权限,并且您是在后台线程中而不是在 UI 线程中发出请求吗?
  • @TonyAllevato 是的,我正在使用 Internet 权限,并且所有内容都在服务中以异步任务运行。还有什么我需要添加的。
  • 我刚刚注意到您的路径是"mnt/sdcard/DCIM/Camera/12232.jpg",这将与您的应用程序运行所在的目录相关。不应该是"/mnt/..."吗?
  • @TonyAllevato 我很抱歉路径以“/mnt/sdcard”开头,这只是一个错字。
  • 我能解决这个问题..谢谢大家

标签: java google-glass google-gdk


【解决方案1】:

您可能需要确保您已查看以下description for media uploading。来自 Google Glass 的开发者网站。

我知道这是基本的(许多堆栈*overflow* 社区成员希望您在发帖之前已经研究过问题),所以您真的应该访问https://developers.google.com/glass

【讨论】:

  • @Android_prp 有帮助吗?
猜你喜欢
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-18
  • 2014-01-04
  • 1970-01-01
  • 2022-12-04
  • 1970-01-01
相关资源
最近更新 更多