问题
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);
...
}
...
}
...
Where am I going wrong?
回答1:
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.
来源:https://stackoverflow.com/questions/21209684/google-glass-upload-files-using-http-client