Google Glass使用http-client上传文件

时间:2014-01-18 20:49:01

标签: java google-glass google-gdk

我正在尝试使用我的Google Glass中的http-client将图像文件上传到我的服务器,但它总是卡在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);
        ...
    }
    ...
}
...

我哪里错了?

1 个答案:

答案 0 :(得分:0)

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

我知道这是基本的(许多堆栈* 溢出 *社区成员更喜欢您在发布此处之前已经研究过问题),所以您真的应该访问https://developers.google.com/glass