wonjsohn / google-glass-api

Automatically exported from code.google.com/p/google-glass-api
0 stars 0 forks source link

post picture/video to a php server on google glass #539

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

1.locate the picture/video in the internal storage of the google glass
2.upload them to the php server

The current output is empty. The expected output is the picture/video files 
uploaded to the php server.

Version: API 19

Current code for uploading a file:
private void postFile(){
        try{
            // the file to be posted
            String textFile = Environment.getExternalStorageDirectory() + "/sample.txt";
            Log.v(TAG, "textFile: " + textFile);
            // the URL where the file will be posted
            String postReceiverUrl = "http://learningzone.me/build/course/en/glass.php";
            Log.v(TAG, "postURL: " + postReceiverUrl);
            // new HttpClient
            HttpClient httpClient = new DefaultHttpClient();
            // post header
            HttpPost httpPost = new HttpPost(postReceiverUrl);
            File file = new File(textFile);
            FileBody fileBody = new FileBody(file);
            MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            reqEntity.addPart("file", fileBody);
            httpPost.setEntity(reqEntity);
            // execute HTTP post request
            HttpResponse response = httpClient.execute(httpPost);
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                String responseStr = EntityUtils.toString(resEntity).trim();
                Log.v(TAG, "Response: " +  responseStr);
                // you can add an if statement here and do other actions based on the response
            }

        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Original issue reported on code.google.com by roi.bu...@gmail.com on 8 Jun 2014 at 9:01