Upload File - Android to Google App Engine (PHP)

2019-03-01 13:30发布

From my Android app to Google App Engine, I'm POSTing a zip file; also I'm POSTing a string. When Google App Engine PHP script runs, I dump the value of $_FILES to the Log by...

ob_start();
var_dump($_FILES);
$result = ob_get_clean();
syslog(LOG_DEBUG, "VAR DUMP\n" . $result . "\n");

I also Log the value of the string. The Log has the string output but doesn't have the $_FILES dumped output. I read THIS LINK, but this seems to pertain to Web. My Android code to POST the file is as follows...

private void postExamplesZipToDrive(File file_zip){
    RequestParams request_params = new RequestParams();
    request_params.put("test", "Came thru");

    //
    try{ request_params.put("file_zip", file_zip); }
    catch(FileNotFoundException e){
        Log.e("postExamplesZipToDrive", "File not found");
        Toast.makeText(this, "Unable to upload.", Toast.LENGTH_SHORT).show();
        return;
    }

    AsyncHttpClient async_http_client = new AsyncHttpClient();

    async_http_client.post(UPLOAD_URL, request_params, new JsonHttpResponseHandler(){
         @Override
         public void onSuccess(int code_status, Header[] headers, JSONArray success) {
            Toast.makeText(getApplicationContext(), "" + code_status, Toast.LENGTH_SHORT).show();
            super.onSuccess(code_status, headers, success);
         }

         @Override
         public void onFailure(int code_status, Header[] headers, String string_response, Throwable throwable){
             Toast.makeText(getApplicationContext(), "" + code_status, Toast.LENGTH_SHORT).show();
             Log.e("onFailure", code_status + "\n" + string_response);
         }
    });
}

My question is, am I POSTing the .zip file correctly? How do I capture the files uploaded that are usually stored in $_FILES?

1条回答
我想做一个坏孩纸
2楼-- · 2019-03-01 14:07

You can use the direct file upload function in php55 (see https://gae-php-tips.appspot.com/2015/03/09/direct-file-uploads-for-php-5-5/).

查看更多
登录 后发表回答