我试图从我的Google Glass上使用http-client将图像文件上传到我的服务器,但它总是卡在httpclient.execute()
方法中。我不知道我应该如何从我的Glass上传文件。这是我到目前为止:Google Glass使用http-client上传文件
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你好我正在使用互联网许可以及一切在服务中运行在一个asynctask.Is还有一些我需要添加。 –
我刚刚注意到你的路径是''mnt/sdcard/DCIM/Camera/12232.jpg“',它与你的应用程序运行的目录有关。不应该是'”/ mnt/... “'? –