Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Google Glass使用http客户端上传文件_Java_Google Glass_Google Gdk - Fatal编程技术网

Java Google Glass使用http客户端上传文件

Java Google Glass使用http客户端上传文件,java,google-glass,google-gdk,Java,Google Glass,Google Gdk,我正试图使用http客户端将一个图像文件从Google Glass上传到我的服务器,但它总是卡在httpclient.execute()方法上。我不知道如何从我的眼镜上传文件。这就是我到目前为止所做的: httpClient = HttpUtils.getNewHttpsClient(); postRequest = new HttpPost(strURL); final File file= new File("mnt/sdcard/DCIM/Camera/12232.jpg");

我正试图使用http客户端将一个图像文件从Google Glass上传到我的服务器,但它总是卡在
httpclient.execute()
方法上。我不知道如何从我的眼镜上传文件。这就是我到目前为止所做的:

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

我哪里做错了?

您可能需要确保已审阅以下内容。来自谷歌眼镜的开发者网站


我知道这是最基本的(许多stack*overflow*社区成员希望您在这里发布之前已经研究过一个问题),所以您真的应该访问。

您是否申请了
INTERNET
权限,您是在后台线程而不是在UI线程中发出请求吗?@TonyAllevato ya我正在使用internet权限,服务中的所有内容都在异步任务中运行。是否还有其他需要添加的内容。我刚刚注意到您的路径是
“mnt/sdcard/DCIM/Camera/12232.jpg”
,这将与应用程序运行的目录相关。是不是应该是
“/mnt/…”
?@TonyAllevato很抱歉路径以“/mnt/sdcard”开头,这只是一个输入错误。我可以解决这个问题。谢谢你all@Android_prp这有用吗?