Google Glass使用http客户端上传文件 [英] Google Glass upload files using http-client

查看:84
本文介绍了Google Glass使用http客户端上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用http-client将图像文件从我的Google Glass上传到服务器,但是它总是卡在httpclient.execute()方法上.我不确定应该如何从Glass上载文件.这是我到目前为止的内容:

I am trying to upload an image file using http-client from my Google Glass to my server but it always gets stuck at the httpclient.execute() method. I am not sure how should I approach uploading files from my Glass. This is what I have so far:

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

我要去哪里错了?

推荐答案

您可能要确保已查看以下

You may want to ensure you have reviewed the following description for media uploading. from the developer site for Google Glass.

我知道这是基本的要求(很多堆栈* 溢出 *社区成员希望您已经在此处发表问题之前研究过问题),因此您确实应该访问

I know this is basic (many stack*overflow* community members prefer that you already have researched a problem before posting here), so you really should visit https://developers.google.com/glass.

这篇关于Google Glass使用http客户端上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆