Java Google Glass使用http客户端上传文件
我正试图使用http客户端将一个图像文件从Google Glass上传到我的服务器,但它总是卡在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");
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这有用吗?